Skip to content

Instantly share code, notes, and snippets.

@chandrikadeb7
Created March 11, 2021 17:30
Show Gist options
  • Save chandrikadeb7/cd839afbcd42e5789400dca78ee43df0 to your computer and use it in GitHub Desktop.
Save chandrikadeb7/cd839afbcd42e5789400dca78ee43df0 to your computer and use it in GitHub Desktop.
LinkedIn-SDERole-HackerRank-Coding Solutions
def rearrange(elements):
# Write your code here
return sorted(elements, key=lambda x:(str(bin(x)).count('1'),x))
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;
}
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;
}
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