Created
March 11, 2021 17:30
-
-
Save chandrikadeb7/cd839afbcd42e5789400dca78ee43df0 to your computer and use it in GitHub Desktop.
LinkedIn-SDERole-HackerRank-Coding Solutions
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def rearrange(elements): | |
# Write your code here | |
return sorted(elements, key=lambda x:(str(bin(x)).count('1'),x)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
static List<Integer> hackerCards(List<Integer> collection, int d) { | |
List<Integer> res = new ArrayList(); | |
int s, e; | |
for(int index = 0; index <= collection.size(); index++) { | |
if(index == 0) | |
s = 1; | |
else | |
s = collection.get(index-1) + 1; | |
if(index != collection.size()) | |
e = collection.get(index); | |
else | |
e = Integer.MAX_VALUE; | |
if(d < s) | |
break; | |
for(int k = s; k < e; k++) { | |
if(k <= d) { | |
res.add(k); | |
d-=k; | |
} | |
else | |
break; | |
} | |
} | |
return res; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static long countMax(List<String> upRight) { | |
//Write your code here | |
long min_Row = Long.MAX_VALUE; | |
long min_Col = Long.MAX_VALUE; | |
for(String str: upRight) { | |
long row = Long.parseLong(str.split(" ")[0]); | |
long col = Long.parseLong(str.split(" ")[1]); | |
min_Row = Math.min(min_Row, row); | |
min_Col = Math.min(min_Col, col); | |
} | |
return minRow * minCol; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static boolean match(int[] arr, int k) { | |
for(int value : arr) { | |
if(value != 0 && value != k) | |
return false; | |
} | |
return true; | |
} | |
public static int perfectSubstring(String s, int k) { | |
//Write your code here | |
int ans = 0; | |
for(int i = 0; i < s.length(); i++) { | |
int[] arr = new int[10]; | |
for(int j = i; j < s.length(); j++) { | |
if(j > i + (10 * k)) | |
break; | |
char c = s.charAt(j); | |
arr[c - '0']++; | |
if(match(arr, k)) | |
ans++; | |
} | |
} | |
return ans; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment