Posts

For those who are in doubt and disappointed

"Choose one activity in your career that can advance your career significantly" When I hear this sentence 4 years ago, I reminded myself that I wanted to conquer the computer algorithm so that I can do better at the interviews. 3 years passed doing nothing and making excuses like "I am so busy in my current job." "I have family to take care of" "I am so tired after work." All of sudden, I woke up and look at myself. I hated my job. I was tired of being underpaid and under estimated by stupid boss and colleagues. I really want to change jobs but there were not many options in my country. So, I decided to do the one thing I knew will change my career. I started studying the computer algorithm. I also started this blog to collect the interview questions and keep my answers to the questions. It wasn't easy to make the regular commitment. Watching online algorithm courses and collecting the interview questions and solving them. Howe...

Given two strings, write a method to decide if one is a permutation of the other

Problem Given two strings, write a method to decide if one is a permutation of the other. Example)  Given two strings, "mom", "grandmom", your algorithm should return True because "mom" is the permutation of "grandmom".

Reading integer streams and return N th order statistics

Image
Problem Imagine you are reading in a stream of integers. Periodically, you wish to be able to look up the rank of a number x (the number of values less than or equal to  x). Implement the data structures and algorithms to support these operations.  The following methods need to be implemented. // method to take new number x void track(int x);  // method to return the number of values that are less than or equal to x (not including x itself) int get_rank(int x);  Example: Stream (in order of appearance): 5, 1, 4, 4,  5,  9, 7, 13, 3 get_rank(1) = 0 get_rank(3) = 1 get_rank(4) = 3

Finding the element in the M X N matrix sorted in ascending order

Problem Given an M $\times$ N matrix in which each row and each column are sorted in ascending order, write a method to find an element.

Finding the string in the sorted array of strings with empty strings

Problem Given a sorted array of strings that is interspersed with empty strings, write a method to find the location of a given string. Example input: find "ball" in  {"at", "", "", "","ball", "", "", "car", "", "". "dad", "",""} Output: 4

Sorting the strings in 20GB file with one string in each line.

Problem Imagine you have a 20 GB file with one string per line. Explain how you would sort strings in the file.

Merge two sorted array A and B, where A has larger buffer to hold B at the end of it.

Problem You are given two sorted arrays, A and B, where A has a large enough buffer at the end to hold B. Write the algorithm to merge A and B without allocation additional memory.