Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 39a6839

Browse files
newProblems
1 parent 3863567 commit 39a6839

9 files changed

+430
-6
lines changed

‎src/Prep/BestPlayerFan.java

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
package Prep;
2+
3+
import java.util.*;
4+
5+
// https://www.hackerearth.com/practice/algorithms/sorting/bubble-sort/practice-problems/algorithm/the-best-player-1/editorial/
6+
7+
class fan implements Comparable<fan> {
8+
9+
10+
String name;
11+
int quote;
12+
13+
public fan(String name, int quote) {
14+
15+
this.name = name;
16+
this.quote = quote;
17+
18+
}
19+
20+
21+
22+
@Override
23+
public int compareTo(fan o) {
24+
25+
if (this.quote == o.quote) {
26+
27+
return this.name.compareTo(o.name);
28+
}
29+
30+
return o.quote - this.quote;
31+
32+
33+
}
34+
35+
}
36+
37+
38+
public class BestPlayerFan {
39+
40+
41+
42+
public static void main(String[] args) {
43+
44+
45+
Scanner sc = new Scanner(System.in);
46+
String temp[] = sc.nextLine().trim().split(" ");
47+
int t = Integer.parseInt(temp[0]);
48+
int i = 0;
49+
int mxfan = Integer.parseInt(temp[1]);
50+
fan[] arr = new fan[t];
51+
while (i < t) {
52+
53+
String inp[] = sc.nextLine().trim().split(" ");
54+
int n = Integer.parseInt(inp[1]);
55+
56+
arr[i] = new fan(inp[0], n);
57+
i++;
58+
59+
}
60+
61+
Arrays.sort(arr);
62+
63+
for (int k = 0; k < mxfan; k++) {
64+
65+
System.out.println(arr[k].name + " " + arr[k].quote);
66+
}
67+
68+
}
69+
70+
71+
}

‎src/Prep/FloorCeil.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,9 @@ public static void helper(int arr[], int x) {
3434
public static void main(String[] args) {
3535

3636

37+
int arr[] = {1, 4, 6, 8, 9};
38+
helper(arr, 3);
39+
3740

3841
}
3942

‎src/Prep/StringPermuteBacktrack.java

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
package Prep;
2+
3+
public class StringPermuteBacktrack {
4+
5+
6+
public static String swapfun(String str, int i, int j) {
7+
8+
char temp[] = str.toCharArray();
9+
10+
char t = temp[i];
11+
temp[i] = temp[j];
12+
temp[j] = t;
13+
14+
return new String(temp);
15+
16+
}
17+
18+
19+
20+
public static void helper(String str, int l, int h) {
21+
22+
23+
if (l == h) {
24+
25+
System.out.println(str);
26+
27+
}
28+
29+
for (int i = l; i <= h; i++) {
30+
31+
32+
str = swapfun(str, l, i);
33+
34+
helper(str, l + 1, h);
35+
36+
str = swapfun(str, l, i);
37+
38+
39+
40+
}
41+
42+
43+
44+
}
45+
46+
47+
public static void main(String[] args) {
48+
49+
helper("ABC", 0, 2);
50+
51+
}
52+
53+
}

‎src/Prep/balancedPartition.java

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
package Prep;
2+
3+
import java.util.Scanner;
4+
5+
// https://www.hackerearth.com/practice/algorithms/sorting/bubble-sort/practice-problems/algorithm/balanced-partition-818edecd/description/
6+
public class balancedPartition {
7+
8+
9+
// public static String helper(String str) {
10+
11+
12+
13+
14+
15+
// }
16+
17+
public static void main(String[] args) {
18+
19+
Scanner sc = new Scanner(System.in);
20+
21+
int t = Integer.parseInt(sc.nextLine().trim());
22+
23+
while (t-- > 0) {
24+
25+
26+
int house = Integer.parseInt(sc.nextLine().trim());
27+
for (int i = 0; i < house; i++) {
28+
29+
30+
int x = sc.nextInt();
31+
int y = sc.nextInt();
32+
int h = sc.nextInt();
33+
34+
35+
36+
37+
}
38+
39+
40+
41+
}
42+
43+
44+
45+
46+
47+
48+
}
49+
50+
}
51+
52+
53+
54+
// v.push_back({y-x,h});
55+
// minn=min(minn,y-x);
56+
// maxx=max(maxx,y-x);
57+
// }
58+
// int l = minn, r = maxx;
59+
// int ans = r + 1;
60+
// bool f = 0;while(l<=r)
61+
// {
62+
// int mid = (l + r) / 2;
63+
// int val = mid;
64+
// int suma = 0, sumb = 0, sume = 0;
65+
// for (int i = 0; i < v.size(); i++) {
66+
// if (v[i].first < val)
67+
// suma += v[i].second;
68+
// else if (v[i].first == val)
69+
// sume += v[i].second;
70+
// else
71+
// sumb += v[i].second;
72+
// }
73+
// if (suma == sumb) {
74+
// f = 1;
75+
// break;
76+
// }
77+
// suma += sume;
78+
// if (suma > sumb) {
79+
// r = val - 1;
80+
// } else if (suma < sumb) {
81+
// l = val + 1;
82+
// } else {
83+
// f = 1;
84+
// break;
85+
// }
86+
87+
// }if(f)cout<<"YES\n";else cout<<"NO\n";
88+
// }return 0;}

‎src/Prep/convertStringcaseDP.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ public static boolean helper(String a, String b) {
2323

2424
if (dp[i][j]) {
2525

26-
if (j <= m && Character.toUpperCase(a.charAt(i)) == b.charAt(j)) {
26+
if (j < m && Character.toUpperCase(a.charAt(i)) == b.charAt(j)) {
2727

2828
dp[i + 1][j + 1] = true;
2929

@@ -50,17 +50,17 @@ public static boolean helper(String a, String b) {
5050
}
5151

5252

53-
public static void main(String[] args) {
5453

54+
public static void main(String[] args) {
5555

5656
Scanner sc = new Scanner(System.in);
5757

58-
int n = sc.nextInt();
58+
int n = Integer.parseInt(sc.nextLine());
5959
while (n-- > 0) {
60-
String a = sc.next();
61-
62-
String b = sc.next();
60+
String a = sc.nextLine();
6361

62+
String b = sc.nextLine();
63+
// System.out.println(a+" "+b);
6464
boolean ans = helper(a, b);
6565

6666
if (ans) {

‎src/Prep/distributeChoco.java

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
package Prep;
2+
3+
import java.util.Scanner;
4+
5+
public class distributeChoco {
6+
7+
8+
9+
public static void main(String[] args) {
10+
11+
12+
Scanner sc = new Scanner(System.in);
13+
14+
int t = sc.nextInt();
15+
16+
while (t-- > 0) {
17+
18+
int c=sc.nextInt();
19+
int n=sc.nextInt();
20+
if (n * (n + 1) / 2 > c) {
21+
System.out.println(c);
22+
}
23+
else {
24+
25+
int k = (c - n * (n - 1) / 2) / n;
26+
System.out.println(c - n * k - n * (n - 1) / 2);
27+
28+
}
29+
30+
}
31+
32+
33+
}
34+
35+
}
36+
37+
38+
// = k + (k + 1) + (k + 2) + . . . . + (k + n - 1)
39+
40+
// = n * k + (1 + 2 + . . . . + n - 1)
41+
42+
// = n * k + n * (n - 1) / 2

‎src/Prep/itsConfidentialEncrypt.java

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
package Prep;
2+
3+
import java.util.Scanner;
4+
5+
public class itsConfidentialEncrypt {
6+
7+
public static String helper(String str) {
8+
9+
if (str.length() <= 2) {
10+
return str;
11+
}
12+
int mid = str.length() / 2;
13+
if (str.length() % 2 == 0) {
14+
mid -= 1;
15+
}
16+
17+
18+
return str.charAt(mid) + helper(str.substring(0, mid)) + helper(str.substring(mid + 1));
19+
20+
21+
22+
}
23+
24+
public static void main(String[] args) {
25+
26+
Scanner sc = new Scanner(System.in);
27+
28+
int t = Integer.parseInt(sc.nextLine().trim());
29+
30+
31+
while (t-- > 0) {
32+
33+
34+
int n = Integer.parseInt(sc.nextLine().trim());
35+
String str = sc.nextLine();
36+
System.out.println(helper(str));
37+
38+
}
39+
40+
}
41+
}

‎src/Prep/jokerAndhisString.java

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
package Prep;
2+
3+
public class jokerAndhisString {
4+
5+
https://www.hackerearth.com/practice/algorithms/string-algorithm/string-searching/practice-problems/algorithm/joker-and-his-string/description/
6+
7+
8+
9+
public static void main(String[] args) {
10+
11+
12+
13+
}
14+
15+
}
16+
17+
18+
// public static void main(String args[] ) throws Exception {
19+
// Scanner sc = new Scanner(System.in);
20+
// String name = sc.nextLine();
21+
// int I = 1;
22+
// int count=0;
23+
// char m = 'a';
24+
// int step = 0;
25+
// for(int i=0;i<name.length();i++) {
26+
// if(name.charAt(i) == m) {
27+
// // System.out.println("Running");
28+
// count++;
29+
// if(count == I) {
30+
// I++;
31+
// count=0;
32+
// int p = (int)m;
33+
// p++;
34+
// m = (char)p;
35+
// }
36+
// }
37+
// else {
38+
// step++;
39+
// }
40+
// // System.out.println(m+"&"+name.charAt(i));
41+
// }
42+
// int ans = step + count;
43+
// System.out.println(ans);
44+
// }

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /