Biweekly
1 experiences · Other (1)
Biweekly Contest 180 - How I solved quickly
Interview Experience
Q1: Just follow instructions, 4 if/else cases Q2: Loop over numbers and then digits of numbers, easiest to use strings (in python) but we could use math too Q3: There is a property known as prime gaps. Basically the gap between primes is smaller than you might think, it’s log based. This means we can literally just simulate incrementing numbers by 1 until we hit a prime or a not prime, rather than using some annoying binary search. Q4: Turn the segments into strings like 111100 1000 1110. We want to put strings with more 1s on the left. If two strings have the same amount of 1s, put the one with fewer 0s on the left. So 110 would go on the left of 1100. Note the edge case if there are no zeroes, we can always put 1s on the very left. Use this custom comparator to sort the strings and we have our number in binary. I think in python the int function can degrade to n\^2 so I looped through each digit and used a modPow function to tally the results.