↳
1) Iterate through the list and create a hashmap of an integer to integer where 1st value is the value in the array and second is the repetition (takes O(n) time). Now iterate through this hashmap and for every value (say a), and assume x is the sum map.get(x-a) * map.get(a) but make sure map.get(x-a) is not null or map.get(x-a) != map.get(a) (if it is then apply combinations as a total amount as C(map.get(a), 2) ). You could either count this or print up to the interviewer, and this iteration will take O(n) worst case. So the algorithm will be linear. There are less efficient ways too such as sort the list (n lgn) and then have an initial loop (n) and then apply quick select(lgn) which would make O(n lgn) again so overall complexity would be O(n lgn). Worst one is brute force where you could have two nested loops and compare every value which would take O(n^2) time 2) needs some clarifications such as how do we understand a node is "swapped"? Weniger
↳
I exp to call me
↳
PSEUDO CODE FOR QUESTION ONE THAT SHALL NOT LIST UNIQUE PAIRS BUT SHALL INCLUDE INVERSE PAIRS TOO... Let Array be ARY of 'n' elements and given Sum be SUM. Let the result be RESULT string. Begin. Initialize RESULT string; Let i and j be integer variables; for (initial value of i=0, while i < or = n, increment i by 1) { for ( initial value j = 0, while j < or = n, increment j by 1) { if ((i not equal to j) and ( if (ARY[i] + ARY[j] ) is equal to SUM)) RESULT = RESULT + " ("+ ARY[i] + ","+ ARY[j] +" )" } } Print RESULT; End. Weniger
↳
public class Test{ public static void main(String args[]){ String Str = new String("konylabsinterview"); System.out.print("Return Value :" ); System.out.println(Str.matches("kon(.*)lab(.*)terview(.*)")); } } Weniger
↳
Use KMP
↳
Hi, Please see if you can provide the details of the question posed in the context of binary search tree. Thanks. Weniger
↳
I came up with a solution where you transpose the array and then exchange the colums. But this is very inefficient. Does anyone have a better solution. Weniger
↳
Let n be the number of rows and m be the number of columns. Make m stacks of (n-1) size, Weniger
↳
Let n be the number of rows and m be the number of columns. Make m stacks of (n-1) size and iterate through your "2D" array by successively pushing entries through stacks: eg. (entry i is being pushed in stack ~(i mod m)) when i reaches m x (n-1) pop stack and overwrite entries in the "2D" array from the beginning until empty + i'th entry then go to the next stack. Repeat until done. this should run in m x (n-1) + m x n = m x (2n +1) and uses m x (n-1) x (data entry mem size) extra memory during the run. If you want to use less memory, it gets a whole lot more complicated but won't be as quick. Weniger
↳
TTL Cache
↳
cream
↳
Through questions like this, interviewers are mostly trying to test your skillset (and its relevance to the role) as robustly as possible, so be prepared for multiple offshoots and followups. It could be a useful exercise to do mocks with friends or colleagues in Careem to get a real sense of what the interview is actually like. Alternatively Prepfully has a ton of Careem Senior Software Development Engineer experts who provide mock interviews for a pretty reasonable amount. prepfully.com/practice-interviews Weniger
↳
Buddy, I think you thinking a bit too complicatedly. A knight on a chess board only has 8 legal moves. and if it is anywhere closer than being atleast 2 boxes from the border it will be less than 8. just take a input of all the pieces on the NxN matrix. check these 8 positions and calculate the probability Weniger
↳
Given in the description above.
↳
Guess what , I got almost the same question on my first interview with Google , and I was applying as a new college grad ....i also can up with a DP solution with O(64m) .... btw can you provide the link to the solution you came across ...?? Weniger
↳
I think you were expected to get details by asking questions which is expected from a experienced professional(Requirement gathering). Weniger
↳
all of them
↳
Hypothetical question
↳
Hhh
↳
Just use an int arr of size 256 and a queue
↳
There's quite an extended back and forth in actual interviews for questions like this, so nothing quite like real practice. The Prepfully Zillow Senior Software Development Engineer experts have actually worked in this role, so they're able to do an honest-to-God accurate mock, which really puts you through the paces. prepfully.com/practice-interviews Weniger
↳
static boolean MyFunc(String term, String input) { int j=0; for(int i=0;i Weniger
↳
static boolean MyFunc(String term, String input) { int j=0; for(int i=0;i Weniger
↳
complexity: computational=O(n) (actually, Theta(n)); disk=O(1). public class MyClass { public static void main(String args[]) { System.out.println("Found = " + myFunc("aba","bbbbbbabbbbbxxxxxab")); System.out.println("Found = " + myFunc("aba","bbbbbbababbbbxxxxxab")); System.out.println("Found = " + myFunc("aba","bbbbbbbbbbabbbbbbbbbbbbbbbaba")); // add @Tests } public static boolean myFunc(String term, String input) { boolean found=false; int j=0,i=0; // Edge cases if(term.length()>input.length()) return false; if(term.length()==0) return true; // O(n): scanning the input while(i Weniger
↳
AB * AB = CAB and not ABC
↳
Just solve it mathematically by considering all possible digits that satisfy this condition at units digit first and then the solution will automatically fall in place. Weniger
↳
If i understood the problem correctly: Repetition is allowed Sol: If you see AB*AB = ABC -> (AB*AB)/AB=C; ->AB = C; so basically you need to find out those values whose multiplication is equal to C and C can not be more than 9: So you will find these : (1,1)(1,2).....(1,9) (2,1)(2,2)(2,3)(2,4), (3,1)(3,2)(3,3),(4,1),(4,2),(5,1)(6,1)(7,1)(8,1)(91) Weniger
↳
Due to personal concerns
↳
I believe we should be genuine while answering these type of questions. Most of the time we change job because of salary. So nothing wrong in mentioning salary as a reason to change. Weniger