Computer Scientist Interview Questions
- 1of 1 vote
AnswersWe are given an unsorted array of n^2 arbitrary numbers, and we must output an n x n matrix of all the inputs such that all the rows and columns are sorted. For example, suppose n=3, n^2=9, and the 9 numbers are just the integers {1,2,...,9}
Possible ouputs include:1 4 7 1 3 5
2 5 8 2 4 6
3 6 9 7 8 9
Show how to sort this array with a Ω(n^2log n) lower bound.
- randyma12 September 14, 2014 in United States| Report Duplicate | Flag | PURGE
Amazon Computer Scientist Algorithm - 1of 1 vote
AnswersGiven an array of integers, but instead of all integers having the same length each can have a different number of bits. For example, the numbers 0 or 1 have 1 bit, 2, 3 have 2 bits, 4,5,6,7 have 3 bits. The TOTAL number of bits of all the integers in the array is n. Describe how to sort the array in O(n) time.
- randyma12 September 14, 2014 in United States| Report Duplicate | Flag | PURGE
Amazon Computer Scientist Algorithm - 0of 0 votes
AnswerHow can we use union find algorithm for finding the path between two points in a Maze
- bharadwajSrivatsa September 13, 2014 in India| Report Duplicate | Flag | PURGE
Samsung Computer Scientist Algorithm - 0of 0 votes
AnswersA hotel manager has to process n advance bookings of rooms for the next season. His hotel has k identifical rooms. Bookings contain
- heliojunior@bct.ect.ufrn.br September 01, 2014 in United States
an arrival date and a departure date. He wants fo find out whether there are enough rooms in the hotel to satify the demand.
Design an algorithm that solves this problem in time O(n logn) . Hint:Consider the set off all arrivals and departures .
Sort the set and process it in sorted order.
Made in Merge Sort| Report Duplicate | Flag | PURGE
US Computer Scientist Algorithm - 0of 0 votes
AnswersJava runs on a "virtual" stack machine inside JVM, which has instruction of size of one byte (called byte-codes). How many instructions/bytecodes potentially can such a machine have?
- rahul23111988 August 22, 2014 in United States
PICK ONE OF THE CHOICES
256
Unlimited
2^32 for 32-bit machines
Depends on JVM version| Report Duplicate | Flag | PURGE
Adobe Computer Scientist Java Operating System - 0of 0 votes
AnswersIn a multi-threaded application, many threads are trying to access the same
- rahul23111988 August 22, 2014 in United States
resource, say a global c ount, g. Threads are synchronized by the following code
(assume lock is a static int variable, initialized to 0 (unlocked state)):
if (lock) wait(); // It's already locked so wait(sleep) till someone wakes me up
else lock=1; // I locked it
/* Critical Section - Increment g */
lock = 0; // Lock released, so wakeup only one of other waiting threads, if any
What is the issue with this synchronization?
PICK ONE OF THE CHOICES
No issues – will work correctly
Works only on a uniprocessor system and would not work on multiprocessor system
Will not work on any system
Cannot say – need more data| Report Duplicate | Flag | PURGE
Adobe Computer Scientist Operating System - 0of 2 votes
AnswersDesign a system like friend's functionality in facebook. should have all features of facebook's friends functionality. like for each person , he can have any number of friends , he will get suggestions for new firends , showing common friends if we visits any other profile . algo should be scalable , robust .
- gopi.komanduri August 02, 2014 in United States| Report Duplicate | Flag | PURGE
Computer Scientist Algorithm Android Application / UI Design Arrays Bit Manipulation C# C++ Cache Coding Computer Architecture & Low Level Data Mining Data Structures Database Distributed Computing Dynamic Programming Hash Table Java Large Scale Computing Linked Lists Math & Computation Object Oriented Design Problem Solving Sorting SQL Stacks System Design Trees and Graphs XML - 5of 5 votes
AnswersHow to find median of a stream of integers....
- Kavita July 08, 2014 in India
interviewer was not interested using insertion sort....
Any better way to do this??| Report Duplicate | Flag | PURGE
Microsoft Computer Scientist - -1of 1 vote
Answers
- Kavita July 07, 2014 in IndiaProgramme 1 class A { private: A() { } }; int main() { //Do not create an object of A } Is there any error Compile Time error Y/N Run Time error Y/N Programme 2 class A { private: A() { } }; class B : public A { }; int main() { //Do not create an object of A or B } Is there any error Compile time Y/N Run Time Y/N
| Report Duplicate | Flag | PURGE
Accenture Computer Scientist - 0of 0 votes
AnswersYou are given an array A = [1, 2, 3, ..., n]:
- praveend806 June 19, 2014 in United States
How many sequences (S1) can you get after exact k adjacent swaps on A?
How many sequences (S2) can you get after at most k swaps on A?
An adjacent swap can be made between two elements of the Array A, A[i] and A[i+1] or A[i] and A[i-1].
A swap otherwise can be between any two elements of the array A[i] and A[j] ∀ 1 ≤ i, j ≤ N, i ≠ j.
Input Format
First and only line contains n and k separated by space.
Output Format
Output S1 % MOD and S2 % MOD in one line, where MOD = 1000000007.
Constraints
1 ≤ n ≤ 2500
1 ≤ k ≤ 2500
Sample Input
3 2
Sample Output
3 6
Explanation
Original array: [1, 2, 3]
1. After 2 adjacent swaps:
We can get [1, 2, 3], [2, 3, 1], [3, 1, 2] ==> S1 == 3
2. After at most 2 swaps:
1) After 0 swap: [1, 2, 3]
2) After 1 swap: [2, 1, 3], [3, 2, 1], [1, 3, 2].
3) After 2 swaps: [1, 2, 3], [2, 3, 1], [3, 1, 2]
==> S2 == 6| Report Duplicate | Flag | PURGE
Achieve Internet Computer Scientist Algorithm - 1of 1 vote
AnswersDivide an array of positive negative integers numbers, print all subsets that have sum = k
- Kavita June 19, 2014 in India
No can be repeated but subsets should be unique
Input:- {2,3,4,1,3,2,6,-1}, Sum = 5
Output:-
2,3
4,1
4,2,-1
6,-1
3,2,1,-1
2,2,1
3,3,-1
may be some more but i want all should be unique
3,2,1,-1 and 2,-1,1,3 are same so i not want u print it two time ...
you cannot store these subsets and later u compare for unique or not using previous generated subsets..| Report Duplicate | Flag | PURGE
Adobe Computer Scientist - 0of 2 votes
Answersint main()
- Kavita June 12, 2014 in India
{
int x = -7;
int y = -2;
cout<<(x%y)<<endl;
return 0;
}
int main()
{
int x = 7;
int y = -2;
cout<<(x%y)<<endl;
return 0;
}
int main()
{
int x = -7;
int y = 2;
cout<<(x%y)<<endl;
return 0;
}| Report Duplicate | Flag | PURGE
Computer Scientist - -2of 2 votes
Answer#include<iostream>
- Kavita June 12, 2014 in India
using namespace std;
int main()
{
int x = -7;
int y = -2;
cout<<(x%y)<<endl;
return 0;
}| Report Duplicate | Flag | PURGE
Computer Scientist - 2of 2 votes
AnswersThe cost of a parallel processing is primarily determined by:(A) Time complexity (B) Switching complexity(C) Circuit complexity
- sukhcharan86 May 19, 2014 in India| Report Duplicate | Flag | PURGE
Computer Scientist - 2of 4 votes
AnswersHow many squares are present in an NxN grid?
- Murali Mohan March 27, 2014 in India
In an MxN grid, how many squares are present and how many rectangles?| Report Duplicate | Flag | PURGE
Amazon Computer Scientist Math & Computation - -1of 1 vote
AnswersThere are 10,000 balls and may be 500 different colors of ball
- zarron January 17, 2014 in United States
Example: There are:
4 - red ball
5900 - Blue ball
3700 - Green ball
396 - mintcream ball
Or there may be 10,000 red balls.
Or all balls are has same range, i.e. 500 red, 500 blue, etc.
We don’t know the range of any ball and number of color balls, but the minimum is 1 color and maximum is 500 colors, and we have auxiliary array of size 500. how to arrange all same color ball together in minimum passes over balls? is it possible to do in less than two passes ??| Report Duplicate | Flag | PURGE
Google Computer Scientist Algorithm - -7of 7 votes
Answersi am working on project and we want to access ASCII value of string at some index But we don't want access chat at index and parse it to integer
- zarron January 12, 2014 in United States
Example:- char character = s.charAt(8);
int ASCII = (int) character;
is there any other way to do same without converting to char?? and what will be time complexity? is there any built in function in java ? i don't know how char store in memory please anyone can explain me ? and how to handle Unicode without converting to char ??
Thanks!!| Report Duplicate | Flag | PURGE
Google Computer Scientist Algorithm - -2of 6 votes
Answerswhat is time complexity of concatenating two int in java example :-
- zarron December 30, 2013 in United States
int a=18965;
int b=78521369741;
after concatenation i want ans in primitive integer data types like,
int c=1896578521369741;
i want to know what is the fastest way to do this and what will be the time complexity ?| Report Duplicate | Flag | PURGE
Google Computer Scientist Algorithm - 0of 0 votes
AnswersLook at the following pseudo-code, which computes the n-th Fibonacci number:
- Eliana December 12, 2013 in United States for games developing
int fibonacci(int n)
{
if (n == 0)
{
print(0)
return 0
}
if (n == 1)
{
print(1)
return 1
}
return fibonacci(n - 1) + fibonacci(n - 2)
}
If one calls fibonacci(3), then the following will happen:
* fibonacci(3) calls fibonacci(2) and fibonacci(1) (the first call).
* fibonacci(2) calls fibonacci(1) (the second call) and fibonacci(0).
* The second call of fibonacci(1) prints 1 and returns 1.
* fibonacci(0) prints 0 and returns 0.
* fibonacci(2) gets the results of fibonacci(1) and fibonacci(0) and returns 1.
* The first call of fibonacci(1) prints 1 and returns 1.
* fibonacci(3) gets the results of fibonacci(2) and fibonacci(1) and returns 2.
In total, 1 will be printed twice and 0 will be printed once.
We want to know how many times 0 and 1 will be printed for a given integer N.
INPUT
The first line contains an integer T, denoting the number of test cases.
The next T lines contain an integer N.
OUTPUT
For each test case, print one line of output which contains 2 integers separated by a space. The first integer is the number of times 0 is printed. The second integer is the number of times 1 is printed.
CONSTRAINTS
1 <= T <= 50
0 <= N <= 40
SAMPLE INPUT
2
0
3
SMAPLEOUTPUT
1 0
1 2| Report Duplicate | Flag | PURGE
Akamai Computer Scientist C++ - 0of 0 votes
AnswersIf you look at the following pseudo-code, which computes the n-th Fibonacci number:
- Eliana December 12, 2013 in United States for games developing
int fibonacci(int n)
{
if (n == 0)
{
print(0)
return 0
}
if (n == 1)
{
print(1)
return 1
}
return fibonacci(n - 1) + fibonacci(n - 2)
}
If one calls fibonacci(3), then the following will happen:
* fibonacci(3) calls fibonacci(2) and fibonacci(1) (the first call).
* fibonacci(2) calls fibonacci(1) (the second call) and fibonacci(0).
* The second call of fibonacci(1) prints 1 and returns 1.
* fibonacci(0) prints 0 and returns 0.
* fibonacci(2) gets the results of fibonacci(1) and fibonacci(0) and returns 1.
* The first call of fibonacci(1) prints 1 and returns 1.
* fibonacci(3) gets the results of fibonacci(2) and fibonacci(1) and returns 2.
In total, 1 will be printed twice and 0 will be printed once.
We want to know how many times 0 and 1 will be printed for a given integer N.
INPUT
The first line contains an integer T, denoting the number of test cases.
The next T lines contain an integer N.
OUTPUT
For each test case, print one line of output which contains 2 integers separated by a space. The first integer is the number of times 0 is printed. The second integer is the number of times 1 is printed.
CONSTRAINTS
1 <= T <= 50
0 <= N <= 40
SAMPLE INPUT
2
0
3
SMAPLEOUTPUT
1 0
1 2| Report Duplicate | Flag | PURGE
Akamai Computer Scientist C++ - 1of 1 vote
AnswersThe way a Knight
- Eliana December 12, 2013 in United States for games developing
Given a chessboard, consisting of n×n cells, several of them are cut. Find the path of minimum length for a Knight from one cell to another. The Knight can’t go through cut cells.
Specifications
Input
The first row is set to the number n (2 ≤ n ≤ 50). Each of the next n lines contains n symbols. The symbol # denotes the cut cell, the point - not cut cell, the symbol @ denotes the initial and final cell of the Knight's path (the chessboard contains two such characters).
Output If the path can not be constructed, print "Impossible". Otherwise display the same map as the input, but check all Knight intermediate positions with symbol @.
Example
Example input
5
.....
.@@..
.....
.....
.....
5
@..@.
..##.
.....
.....
.....
5
@....
..#..
.#...
.....
....@
Example output
Sample 1
...@.
.@@..
....@
.....
.....
Sample 2
@..@.
..##.
.@..@
..@..
@....
Sample 3
Impossible| Report Duplicate | Flag | PURGE
Akamai Computer Scientist C - -1of 1 vote
Answersfind the 3 most repeated numbers in a given array.
- guptasunny158 September 22, 2013 in India| Report Duplicate | Flag | PURGE
Amazon Computer Scientist - 10of 10 votes
Answershow to merge two binary search tree into balanced binary search tree.. Let there be m elements in first tree and n elements in the other tree. Your merge function should take O(m+n) time with in constant space.
- vivek August 11, 2013 in United States
Examples:
A Balanced BST 1
90
/ \
70 110
A Balanced BST 2
60
/ \
5 800
output :-->
70
/ \
60 90
/ \
5 800| Report Duplicate | Flag | PURGE
Google Computer Scientist Algorithm - 0of 0 votes
AnswersFind lowest common ancestor of two nodes in a binary tree iteratively. Root in the binary search tree is not given.
- guptasunny158 August 10, 2013 in India| Report Duplicate | Flag | PURGE
Adobe Computer Scientist Algorithm - -3of 3 votes
Answersplease read full question before ans,
- vivek August 01, 2013 in United States
time complexity to merge k sorted arrays of size n each where space is not constraint and merge them with in m swap( m is total no of element i.e m=k*n )
Example:
Input:
k = 5, n = 4
arr[][] = { {3, 33, 55, 71},
{29, 63, 64, 88},
{100,999, 1100, 1800}
{18,99, 155, 180}
{360,480, 590, 620}} ;
Output: 3 18 29 33 55 63 64 71 88 99 100 155 180 360 480 590 620 999 1100 1800
==> ( " sort this array with in 15 swap or insertion ")| Report Duplicate | Flag | PURGE
Microsoft Computer Scientist Algorithm - 0of 0 votes
AnswersHow can I find if a String exists in a double dimension Array. For eg. Does CAT exist in
- Abhi March 04, 2013 in United States
'c','b','k'
'd','a','l'
'g','t','i'
It does exist. What will be an optimal way to do it ?
Assume you don't have to move upwards in the Array.
So in the below Array cat does not exist.
'c','b','t'
'd','a','l'
'g','J','i'| Report Duplicate | Flag | PURGE
Adobe Computer Scientist Algorithm - -1of 1 vote
AnswerHow can we implement search a keyword in using selected websites?
- Amrita.Sahasrabudhe January 27, 2013 in India
I want to know How to implement following tech stuff. And I want to know any existing api / plugin/ ready to use logic is available for this.
I want to design custom search engine which can search to specific websites.
and we can add/edit/delete websites from search results.
Like In a google if we want to search a keyword from 5 diff sites
"best ecommerce" site:www.A.com OR site:www.B.com OR site:www.C.com OR site:www.D.com OR site:www.E.com
So we get result from this sites only.
So Please letme know is there any plugin available in wordpress, .net, etc| Report Duplicate | Flag | PURGE
Computer Scientist - 0of 0 votes
AnswersYou do have two linked list L1 and L2. The size of linked lists is huge and in billions. Linked List contains numbers (both negative and positive). For simplicity you can assume they are all integers.
- Geek December 09, 2012 in United States
You have been given a number say N. now you need to find out all of the pairs where one element from L1 + one element from L2 = N.
i.e.
L1 = 28, -7, 0, 56, 6, -8, 0, 72, 1000, -33
L2 = 53, 20, 27, -52, 99, 14, -8
N = 20
The answer will be:
(28, 8), (-7, 27), (0, 20), (6, 14), (0, 20), (72, -52)
more questions at http://dsalgointerview.wordpress.com/| Report Duplicate | Flag | PURGE
Adobe Computer Scientist Algorithm