Skip to content

Commit 468f490

Browse files
committed
Some refactorings
1 parent 849fb16 commit 468f490

File tree

62 files changed

+147
-140
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

62 files changed

+147
-140
lines changed

src/main/java/com/hackerrank/algorithms/strings/MakingAnagrams.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ public class MakingAnagrams {
1818
* @return
1919
*/
2020
public static int makeAnagrams(String a, String b) {
21-
21+
2222
int i = 0, j = 0, c = 0;
2323
char[] s1 = a.toCharArray();
2424
char[] s2 = b.toCharArray();

src/main/java/com/hackerrank/interviewpreparation/arrays/DS2DArrayProblem.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,10 @@ public class DS2DArrayProblem {
1616
private static int hourglassSum(int[][] arr) {
1717
int maxSum = Integer.MIN_VALUE;
1818
int hourglassSum;
19-
for (int i=0;i<arr.length-2;i++) {
20-
for(int j=0;j<arr[0].length-2;j++) {
21-
hourglassSum = arr[i][j] + arr[i][j+1] + arr[i][j+2] + arr[i+1][j+1] +
22-
arr[i+2][j] + arr[i+2][j+1] + arr[i+2][j+2];
19+
for (int i = 0; i < arr.length - 2; i++) {
20+
for (int j = 0; j < arr[0].length - 2; j++) {
21+
hourglassSum = arr[i][j] + arr[i][j + 1] + arr[i][j + 2] + arr[i + 1][j + 1] +
22+
arr[i + 2][j] + arr[i + 2][j + 1] + arr[i + 2][j + 2];
2323
if (hourglassSum > maxSum) {
2424
maxSum = hourglassSum;
2525
}

src/main/java/com/hackerrank/projecteuler/MultiplesOf3and5.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ public class MultiplesOf3and5 {
1313

1414
public static void main(String a[]) {
1515
Scanner in = new Scanner(System.in);
16-
16+
1717
int t = Integer.parseInt(in.nextLine());
18-
18+
1919
}
2020
}

src/main/java/com/rampatra/arrays/CelebrityProblem.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
* In a party of N people, only one person is known to everyone. Such a person may be present in the party, if yes,
1414
* (s)he doesn’t know anyone in the party. We can only ask questions like “does A know B? “. Find the stranger
1515
* (celebrity) in minimum number of questions.
16-
*
16+
* <p>
1717
* TODO: Not tested.
1818
*/
1919
public class CelebrityProblem {
@@ -44,7 +44,7 @@ public static boolean haveAcquaintance(int[][] peoples, int a, int b) {
4444
* - Push the remained person onto stack.
4545
* - Repeat step 2 and 3 until only one person remains in the stack.
4646
* - Check the remained person in stack does not have acquaintance with anyone else.
47-
*
47+
*
4848
* @param peoples
4949
* @return
5050
*/

src/main/java/com/rampatra/arrays/EqualProbabilityRandomNoGenerator.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
/**
77
* Given a random number generator f(n) which generates a random number
88
* from {@code 0} (inclusive) to {@code n} (exclusive), design a method
9-
* which uses f(n) to generate non repeating random numbers from
9+
* which uses f(n) to generate non repeating random numbers from
1010
* {@code 0} (inclusive) to {@code n} (exclusive)?
1111
*
1212
* @author: ramswaroop
@@ -19,9 +19,9 @@ public class EqualProbabilityRandomNoGenerator {
1919
static int size;
2020

2121
/**
22-
* The algorithm is to create a bucket of numbers and then to keep on
22+
* The algorithm is to create a bucket of numbers and then to keep on
2323
* removing the elements from the bucket which are returned.
24-
*
24+
*
2525
* @return
2626
*/
2727
public static int getRandom() {
@@ -37,12 +37,12 @@ public static int f(int n) {
3737

3838
public static void main(String a[]) {
3939
Scanner in = new Scanner(System.in);
40-
40+
4141
System.out.println("How many random numbers you would like to generate?");
4242
size = in.nextInt();
43-
43+
4444
bucket = new int[size];
45-
45+
4646
for (int i = 0; i < bucket.length; i++) {
4747
bucket[i] = i;
4848
}

src/main/java/com/rampatra/arrays/IntersectionAndUnionOf2SortedArrays.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@
1212
public class IntersectionAndUnionOf2SortedArrays {
1313

1414
/**
15-
* Returns a 2-D array consisting of intersection and union of
15+
* Returns a 2-D array consisting of intersection and union of
1616
* two sorted arrays {@param a} and {@param b} respectively.
17-
*
17+
*
1818
* @param a
1919
* @param b
2020
* @return
@@ -24,7 +24,7 @@ public static int[][] getIntersectionAndUnionOf2SortedArrays(int[] a, int[] b) {
2424
int[] intersection = new int[length], union = new int[length];
2525

2626
for (int i = 0, j = 0; i < a.length || j < b.length; ) {
27-
27+
2828
// if either of the arrays runs out first
2929
if (i == a.length) {
3030
union[y++] = b[j++];

src/main/java/com/rampatra/arrays/InversionsInArray.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ public static int getInversionCountNaiveApproach(int[] a) {
4040

4141
/**
4242
* Optimized approach.
43-
*
43+
* <p>
4444
* Explanation: In merge() if a[i] > b[j] then all elements in array a starting
4545
* from i are greater than b[j] which equals to the number of inversions for
4646
* the two sub-arrays.

src/main/java/com/rampatra/arrays/KLargestElements.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,17 +15,17 @@ public class KLargestElements {
1515

1616
/**
1717
* Finds {@param k} largest elements in array {@param a}.
18-
*
18+
* <p>
1919
* Algorithm:
2020
* 1) Build a Min Heap MH of the first k elements (arr[0] to arr[k-1]) of the given array. This takes O(k) time.
21-
*
21+
* <p>
2222
* 2) For each element, after the kth element (arr[k] to arr[n-1]), compare it with root of MH.
2323
* ……a) If the element is greater than the root then make it root and call buildHeap for MH
2424
* ……b) Else ignore it.
2525
* This step takes (n-k) * O(k) time.
26-
*
26+
* <p>
2727
* 3) Finally, MH has k largest elements and root of the MH is the kth largest element.
28-
*
28+
* <p>
2929
* Therefore, the total time complexity of the above algorithm is: O(k) + (n-k) * O(k).
3030
*
3131
* @param a

src/main/java/com/rampatra/arrays/KthLargestElement.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ public static int getKthLargestElement(int[] a, int k) {
4444
maxHeap.buildMaxHeap();
4545
while (true) {
4646
if (k == 1) break;
47-
47+
4848
maxHeap.extractMax();
4949
k--;
5050
}

src/main/java/com/rampatra/arrays/LargestProductContiguousSubArray.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
public class LargestProductContiguousSubArray {
1111

1212
/**
13-
*
1413
* @param a
1514
* @return
1615
*/

0 commit comments

Comments
 (0)