Saurabh
BAN USER- 0of 0 votes
AnswersFind unique integers from list of integers
# Question # Write a function that will return an array of integers that occur exactly once in a given array of integers. # e.g. For a list [1,2,3,5,2,2,3,4], return [1,5,4] since they appear once (order does not matter). def once_integers(integers):
Follow up:
Optimize the code if input is sorted.
- Saurabh in United States for Software Developement - Tools# What if the input is sorted, such as [1,2,2,2,3,3,4,5], could the algorithm be further optimized # (e.g. space complexity)? def once_integers_sorted(integers):
| Report Duplicate | Flag | PURGE
Linkedin Software Developer - 0of 0 votes
AnswersString Rotation. Given two string check if String1 is rotating match for String2
- Saurabh in United States for Software Developement - Tools# Given two strings. Write a function that will return true if one string is a rotation of the other string. # e.g. 'bca' and 'cab' are rotations of 'abc' and the function should return true # 'barbazfoo', 'oobarbazf' and 'rbazfooba' are rotations of 'foobarbaz' def is_rotation(string1, string2):
| Report Duplicate | Flag | PURGE
Linkedin Software Developer Algorithm
Does it have to be this complex? Question was asked in Phone interview!!
Inspired from form solution posted by @Harsha.
1. Is raceTo less than equal to Max num available in Pool
2. Is difference between raceTo and Max num available in Pool greater than 2nd largest number? If yes pick Max number else pick smallest number.
This is python code for pickNum everything else is same as @Harsha's code.
def __pick_num(self, race_to):
if self.__pool[-1] >= race_to:
return self.__pool.pop()
if race_to - self.__pool[-1] > self.__pool[-2]:
return self.__pool.pop()
else:
return self.__pool.pop(0)
I might be missing something obvious. Let me know if there are any cases which this cannot handle.
- Saurabh September 18, 2016
Do remember that this solution will break if there are zeros in an array. These are special cases which interviewer looks for us to handle.
Here is sample code (similar solution) which handles zero possibility.
- Saurabh October 09, 2016