## Recent Interview Questions

- -1of 1 vote
Traveling Salesman Problem

- 1of 1 vote
Whats the time complexity of this code?

When I told him its O(N^3), he told me to look carefully, its O(N^2),

I dont know why? Any idea?`for (int i = 0; i < n-2; ++i) { //some code for (int j = i+1; j < n-1; ++j) { //some code for (int k = j+1; k < n; ++k) { //some code } }`

}

- 0of 0 votes
Define a class Marks as having the fields marks1, marks2, marks3 and maxMarks all of type int.

In the class Marks

- define a constructor of the class whch takes 3 ints as input and assigns them to marks1, marks2 and mark3 respectively. It aslo assigns the maximum of marks1, marks2 and marks3 to maxMarks.

- define a method getMaxMarks() which returns the maximum of marks1, marks2 and marks3.

- define a method isPass() which returns true if the average of marks1, marks2 and marks3 is at least 40.

Define a class StudentList which has the field allMarks(of type Marks[]). In the class, define the methods

- totalStudents() which returns the number of total students which is the number of objects in the array allMarks

- passCount() which returns the number of students who have passed.

- 0of 0 votes
Define a class Point having 2 fields x (int) and y (int) which represents a point (x,y)

Define a class Line having 2 Points, pt1 and pt2.

Define a class Quadrilateral having 4 Points, pt1, pt2, pt3 and pt4. The class also has the following functions

- getAllLines() which returns a Line[] consisting all 4 lines of the Quadrilateral. Note that the 4 lines of the quadrilateral will be pt1:pt2, pt2:pt3, pt3:pt4 and pt4:pt1

- longestSide() which return a Line that represents the longest the side of the Quadrilateral.

Also define the constructors for each class

- 0of 0 votes
Define a class Marks as having the fields marks1, marks2, marks3 and maxMarks all of type int.

In the class Marks

- define a constructor of the class whch takes 3 ints as input and assigns them to marks1, marks2 and mark3 respectively. It aslo assigns the maximum of marks1, marks2 and marks3 to maxMarks.

- define a method getMaxMarks() which returns the maximum of marks1, marks2 and marks3.

- define a method isPass() which returns true if the average of marks1, marks2 and marks3 is at least 40.

Define a class StudentList which has the field allMarks(of type Marks[]). In the class, define the methods

- totalStudents() which returns the number of total students which is the number of objects in the array allMarks

- passCount() which returns the number of students who have passed.

- 0of 0 votes
They conducted a hiring round and this was asked there ?

Hi friends This question was asked in recent hiring challenge at hackerearth , that is over now,Please discuss your strategies.I am not able to devise algorithm please provide some hints to solve it.

Pulkit is really good at maths. Recently, he came to know about a problem on matrices. Amazed by the problem he got, he asked Ashish the same problem. Ashish also being good at maths solved the problem within 5 minutes. Now, its your time to solve the problem.

You will be given n*m binary matrix. You need to tell if it is possible to delete a column such that after deleting that column, rows of the matrix will be unique. If yes than print "Yes" else print "No".

[Input]

First line contains an integer t denoting no.of test cases.

Next line contains 2 integers n and m denoting no.of rows and columns.

Next n line contains binary string of length m each.

[Output]

For each test case output "Yes" or "No".

[Constraints]

1<=t<=100

1<=n<=1000

2<=m<=1000

Sample Input (Plaintext Link)

2

3 3

101

000

100

2 2

11

11

Sample Output (Plaintext Link)

Yes

No

- 0of 0 votes
Given a 2-dimensional array with arbitrary sizes and contains random positive values, you are required to move from the first element [0][0] to the last element [n][n] using the path which will yield the maximum sum of all the elements traversed. You can only move right and down; NOT left and up.

- 0of 0 votes
How can we get square of a number without using * or carrot sign.

- 0of 0 votes
Write a query which return 5 persons who had spent most from a table and table contains customer id, product id and expenses. Customer id can be duplicate.

- 0of 0 votes
There is 3 text file, like file1.txt, file2.txt etc. Every file contains customer id, product id and expenses. Now write java code which will return 5 persons who spent most in these three files. Customer id can be duplicate all over files.

- 0of 0 votes
How can we get the square of a number without using * or carrot sign.

- 1of 1 vote
Design a Meeting Reminder Pop-up similar to one found on outlook.

Data Structure to be used and come up with classes.

- 0of 2 votes
JAVA:

Given an array say of length 1000; Pick up every value from every 20th index and store it in a separate array. Make sure to loop through all the elements in the array. Example: newArray1 = {0, 20, 40, 60, ..};

newArray2 = {1, 21,41, 61, ..};

- 0of 0 votes
Given an array say of length 1000; Pick up every value from every 20th index and store it in a separate array. Make sure to loop through all the elements in the array. Example: newArray1 = {0, 20, 40, 60, ..};

newArray2 = {1, 21,41, 61, ..};

- 0of 0 votes
Given a binary tree,Write a function to return all of the nodes from a given node and a given distance. The function has three parameters root, the given node and the given distance. For example

5

/\

4 7

/\

6 10

\

12

Calling the function F(root,7,1) will the return all the nodes from node 7 with the distance 1 which is 6,10,5

another example is F(root.7,2) will the return nodes 12,4

- 0of 0 votes
Write a function to return all of the nodes from a given node and a given distance. The function has three parameter root, the given node and the given distance. For example

5

/\

4 7

/\

6 10

\

12

Calling the function F(root,7,1) will the return all the nodes from node 7 with the distance 1 which is 6,10,5

another example is F(root.7,2) will the return nodes 12,4

- 0of 0 votes
Give a Binary tree, write a function to return all the nodes from a given with a given distance. The function has three parameters root of tree, a given node, a given distance. For example,

5

/\

4 7

/\

3 10

\

12

calling the function F(root,7,1) will return nodes 3,5,10

calling F(root,7,2) will return nodes 12,4

- 1of 1 vote
There is a compressed string eg. ”ab2c3”, the string has lowercase characters and numbers. We can uncompress the given string as follows: whenever we get a number “n” in the string, the portion of the string before the number will repeat “n” times. So in the above example, we get a 2, so string will become “ababc3”, now we get a 3, so final string will be “ababcababcababc”.

Given a compressed string and a number k, you have to output the k’th character in the uncompressed string.

1 <= length of string <= 1500

1 <= n <= 1000

1 <= k < 2^31

example:

input: ab2c3 10

output: c

- -1of 1 vote
Implement a function to return top rated movies in the network of movies reachable from the current movie.

`* eg. A(Rating 1.2) * / \ * B(2.4) C(3.6) * \ / * D(4.8)`

In the above example, edges represent similarity and the number is rating.

* getMovieRecommendations(A,2) should return C and D (sorting order doesn't matter so it can also return D and C)

* getMovieRecommendations(A,4) should return A, B, C, D (it can also return these in any order eg: B,C,D,A)

* getMovieRecommendations(A,1) should return D. Note distance from A to D doesn't matter, return the highest rated.`import java.util.ArrayList; import java.util.List; public class Movie { private final int movieId; private final float rating; private List<Movie> similarMovies; // Similarity is bidirectional public Movie(int movieId, float rating) { this.movieId = movieId; this.rating = rating; similarMovies = new ArrayList<Movie>(); } public int getId() { return movieId; } public float getRating() { return rating; } public void addSimilarMovie(Movie movie) { similarMovies.add(movie); movie.similarMovies.add(this); } public List<Movie> getSimilarMovies() { return similarMovies; } /* * * @param movie * @param numTopRatedSimilarMovies * number of movies we want to return * @return List of top rated similar movies */ public static List<Movie> getMovieRecommendations(Movie movie, int numTopRatedSimilarMovies) { // Implement me return null; } }`

- -2of 2 votes
Given an array of positive and negative numbers, arrange them in an alternate fashion such that every positive number is followed by negative and vice-versa maintaining the order of appearance.

Number of positive and negative numbers need not be equal. If there are more positive numbers they appear at the end of the array. If there are more negative numbers, they too appear in the end of the array.*

Example:`Input: arr[] = {1, 2, 3, -4, -1, 4} Output: arr[] = {-4, 1, -1, 2, 3, 4} Input: arr[] = {-5, -2, 5, 2, 4, 7, 1, 8, 0, -8} output: arr[] = {-5, 5, -2, 2, -8, 4, 7, 1, 8, 0}`

Limitations:

a) Use O(1) extra space

b) Time Complexity should be O(N)

c) Maintain the order of appearance of elements as in original array.

- 0of 0 votes
In a given string of 0s and 1s , if you flip only one 0 to 1 , what would be the longest contiguous string of 1s possible. e.g

{0 01 0 11010 0} the answer would be 4 and attained by flipping bit number 7 form 0 to 1 . Came up with O(n2) , expected was O(n)

- 0of 0 votes
On a very large rotated sorted array with one or more duplicates, find the index of a particular number: 20,30,30,45,60,60,5,17,17,19

- 0of 0 votes
How would you architect a client based recommendation feature(based on customer history) on product detail page?

- 0of 0 votes
Design Customers who viewed this also viewed that for an online shopping portal

- 0of 0 votes
. In an unsorted array of numbers that occurs an odd number of times except one that occurs an even number of times, find the number that occurs an even number of times

- 0of 0 votes
Design a thread safe hash table from ground up.

Follow up question: How do you design it without using any locks.

- 0of 0 votes
Given a doubly linked list, copy the list.

- 0of 0 votes
(To write in Objective-C; I will write the EXACT question)

Given a dictionary of words, return an array of the words whose match. (i.e. pattern "c.t" match with "cat", "cut", etc. because the dot notation stand for ANY character).

SUGGEST: use suffix tree, for(for()) is not a good solution.

- 0of 0 votes
Print the output of linked list in the reverse order without altering the actual linked list.

First try it without recursion and then with recursion

Original linked list A->B->C->D

Output should be DCBA

- 0of 0 votes
Algorithm to check whether given sequence is arithmetic progression or geometric progression