Nascent
BAN USER
- 0of 0 votes
AnswersGiven a dictionary containing some words, and a start word and end word, you need to find the minimum number of conversion needed to convert start word to end word with the following restrictions :-
- Nascent in India
1. Each intermediate word must be in the dictionary
2. You can change only one character in the word to convert to another word.
Example If You are given start word as ‘SAT’ and end word as ‘PAN
and the dictionary contains words = [‘RAT’,’PAT’,’DAM’]
then SAT -> PAT ->PAN is the answer.| Report Duplicate | Flag | PURGE
Walmart Labs - 0of 0 votes
AnswersDesign amazon's frequently viewed product page.
- Nascent in India| Report Duplicate | Flag | PURGE
Amazon SDE-2 - 0of 0 votes
AnswersHow will you design a true collar?
- Nascent in India| Report Duplicate | Flag | PURGE
Microsoft SDE-2 - 0of 0 votes
AnswersHow will you implement a dictionary.
- Nascent in India| Report Duplicate | Flag | PURGE
Microsoft SDE-2 - 0of 0 votes
AnswerDesign a monitoring system for hotel booking site. Proper oops design.
- Nascent in India| Report Duplicate | Flag | PURGE
Microsoft SDE-2 - 0of 0 votes
AnswersDesign a chat application. How will u handle huge data?
- Nascent in India| Report Duplicate | Flag | PURGE
Amazon SDE-2 - 0of 0 votes
AnswersDesign an online pizza delivery system. Complete OO Design needed.
- Nascent in India| Report Duplicate | Flag | PURGE
Amazon SDE-2 - 0of 0 votes
AnswersGiven two strings. Figure out if 2nd one is substring of 1st one. 2nd may contain wildcard characters like '*','?' etc
- Nascent in United States| Report Duplicate | Flag | PURGE
Amazon - 0of 0 votes
AnswersWrite a recursive function to print directory structure. Two function were given isfolder() and openfolder().
- Nascent in United States| Report Duplicate | Flag | PURGE
Amazon - 0of 0 votes
AnswersGiven a file which contains large number of strings.
- Nascent in India
e.g.:my name is XYZ. My emansi XYZ i.e. it has words and reverse of words. There can be the case where no reverse word is present.He told me to print all those pair whose reverse is also present in the file.
For above example output will be:
{name,eman}, {is, si}
Constraints were Minimum space should be used and time complexity should be minimum, further he added don’t compute reverse of string at all.| Report Duplicate | Flag | PURGE
Amazon - 0of 0 votes
AnswersAn input file called input.txt consists of data in the following format:
- Nascent in India
22 Data Structures 45
23 Maths 2 52
23 Maths 3 57
22 English 51
26 Data Structures 72
23 Data Structures 63
26 English 81
Each line consists of three fields "Student ID," "Subject," and "Marks." "Student ID" and "Marks" are integers and "Subject" is a string that does not contain '|' or newlines (but might contain digits). There can be any number of students and up to 6 subjects. You have to read this file, and print the average marks in "Data Structures," across all students.
Thus for the above file, the output would be:
60
Kindly let me know the soln in C#.| Report Duplicate | Flag | PURGE
Microsoft - 2of 2 votes
AnswersA string can contain 0 to n(input) number in sorted form find all the transition point.
- Nascent in India| Report Duplicate | Flag | PURGE
Amazon - 1of 1 vote
AnswersGiven a BST, find out the minimum length form root to leaf with sum S. Note that:
- Nascent in India
a) Path from root to leaf node.
b) Sum of node of the path is S.
c) if multiple such path exist, print minimum length path.
d) What is advantage of BST rather than BT used for this algorithm, how it improve the performance. in BST, is it required to explore both side ?| Report Duplicate | Flag | PURGE
Microsoft SDE1 - 0of 0 votes
AnswersYou are given a 2D grid in which each cell is either empty, contains an entry “D” which stands for Door, or an entry “W” which stands for wall (Obstacle). You can move in any of the four directions from each empty position in the grid. Of course you cannot move into a cell that has “W” in it. You need to fill each empty cell with a number that represents the distance of the closest door to that cell.
- Nascent in India| Report Duplicate | Flag | PURGE
Amazon - 0of 2 votes
Answerdesign e commerce web site like amazon....
- Nascent in United States| Report Duplicate | Flag | PURGE
Amazon - 1of 1 vote
AnswersGiven an nxn screen, Each pixel is represented by intensity values. Given a specific pixel as an input, find the no. of pixels of the same colour which can reached from this pixel. Assume any suitable data structure for a screen.
- Nascent in United States| Report Duplicate | Flag | PURGE
Amazon - 0of 0 votes
AnswersGiven a sorted 2D matrix. Find the median.
- Nascent in India| Report Duplicate | Flag | PURGE
Amazon - 0of 0 votes
AnswersA node which has following fields
- Nascent in United States
a) data
b) next_ptr
c) prev_ptr
can be used to represent doubly linked list, binary tree or none. Given a random pointer recognize whether it forms DLL, Binary Tree or none.| Report Duplicate | Flag | PURGE
Microsoft - 0of 0 votes
AnswersConsider a binary tree for which root node and a target node are given to you. Give the next sibling of the target.(let the target be in level k, then you need to give the immediate node which is in level k)
- Nascent in United States| Report Duplicate | Flag | PURGE
Microsoft - -1of 1 vote
AnswersWAP to print the longest bitonic sequence in an array.
- Nascent in United States| Report Duplicate | Flag | PURGE
Amazon - 2of 6 votes
AnswersGiven an array of n numbers with repetition of numbers. You need to find the max length of continuous sub array with at max 3 unique elements.
- Nascent in India
For eg
array: 1 2 3 1 4 3 4 1 2
ans: 6 (3 1 4 3 4 1)
Solution: Time complexity O(n)
Extra Space O(1)| Report Duplicate | Flag | PURGE
Amazon - 0of 0 votes
AnswersGiven a function rand5() which generated random numbers from 0 to 5. Use this function to create rand7(). In deep approach was asked and further discussion was made regarding how to generalize it for creating m random no generator from n randon number generator. Plz give solution with proper explanation.
- Nascent in India| Report Duplicate | Flag | PURGE
Amazon - 1of 1 vote
AnswersImplement a stack that pops out the most frequently added item.
- Nascent in India| Report Duplicate | Flag | PURGE
Amazon - 1of 5 votes
AnswersYou have a huge set of stars as three dimensional coordinates. How would you find the k closest stars?
- Nascent in United States| Report Duplicate | Flag | PURGE
Amazon - 0of 0 votes
AnswersWhat do you mean by a 32 bit OS. Explain in details.
- Nascent in India| Report Duplicate | Flag | PURGE
Amazon - 0of 0 votes
AnswersFind two's compliment of a negative number. Code it.
- Nascent in India| Report Duplicate | Flag | PURGE
Amazon - 3of 3 votes
AnswersThere is a clock at the bottom of the hill and a clock at the top of the hill. The clock at the bottom of the hill works fine but the clock at the top doesn’t. How will you synchronize the two clocks. Obviously, you can’t carry either of the clocks up or down the hill! And you have a horse to help you transport yourself. And, the time required for going up the hill is not equal to the time required to go down the hill.
- Nascent in United States| Report Duplicate | Flag | PURGE
Amazon - 0of 0 votes
AnswersConstruct ancesstor matrix of a given binary tree.
- Nascent in India| Report Duplicate | Flag | PURGE
Amazon - 0of 0 votes
AnswersDesign a singleton design pattern.
- Nascent in India| Report Duplicate | Flag | PURGE
Amazon Software Engineer / Developer - 0of 0 votes
AnswersDesign a class in C++ such that only one object of it can be created.
- Nascent in India| Report Duplicate | Flag | PURGE
Amazon Software Engineer / Developer - 0of 0 votes
AnswersDesign a DS for storing browsing history.
- Nascent in United States| Report Duplicate | Flag | PURGE
Amazon Adobe Software Engineer / Developer - 0of 0 votes
AnswersGiven a sentence and a function isValidDictionaryword(String s), which returns true if the word is present in dictionary. WAP to separate valid dictionary words in the sentence with a space.
- Nascent in India
I/P : thereisastoneontheroad.
O/P : there is a stone on the road.| Report Duplicate | Flag | PURGE
Amazon Software Engineer / Developer - 0of 0 votes
AnswersGiven 2 BSTs. Find the largest common bst between them.
- Nascent in India| Report Duplicate | Flag | PURGE
Amazon Software Engineer / Developer - 0of 0 votes
AnswersWAP to print k closest points in a plane having n points (2D).
- Nascent in India| Report Duplicate | Flag | PURGE
Amazon Software Engineer / Developer - 0of 0 votes
Answersfind 10 most frequently occurring words in a given file.
- Nascent in India| Report Duplicate | Flag | PURGE
Adobe Software Engineer / Developer - 0of 0 votes
AnswersGiven an array of integers. Re arrange the numbers such that odd numbers occupy odd position and even numbers occupy even position. The order of numbers should not change and it is to be done in-place.
- Nascent in India| Report Duplicate | Flag | PURGE
Adobe Software Engineer / Developer - 0of 0 votes
Answers: Design a data structure for the following operations:
- Nascent in India
I. Enqueue
II. Dequeue
III. Delete a given number(if it is present in the queue, else do nothing)
IV. isNumberPresent
All these operations should take O(1) time| Report Duplicate | Flag | PURGE
Amazon Software Engineer / Developer Algorithm
Using this method we can find the absolute minimum difference:
Assume numbers are array a[ ].
for(int i=1;i<(sizeof(a)/sizeof(int));i++)
{
min=a[1]-a[0];
max=a[0];
if((a[i]-min)<min)
{
min=a[i]-max;
start=a[i];
end=max;
}
if(a[i]>max)
max=a[i];
}
after finding absolute min we can get the elements using start and end.
but since we need to find all. After getting the absolute minimum we will traverse the liist and find out two numbers having difference equal to absolute min.
#include<iostream>
using namespace std;
int main()
{
int a[]={3,3,2,1,1};
cout<<"repeated:"<<endl;
for(int i=0;i<5;i++)
{
if((a[abs(a[i])-1]) > 0)
{
a[abs(a[i])-1]=- a[abs(a[i])-1];
}
else
{
cout<<a[i]<<endl;
}
}
cout<<"missing:"<<endl;
for(int i=0;i<5;i++)
{
if(a[i]>0)
cout<<i+1<<endl;
}
getchar();
return 0;
}
I think this question is similar to the closest pair in a given set of point. Instead of taking the mid point we consider the given point p(x,y) and compute the points based on x co-ordinate which are closest. Repeat for the closest point with the y - co ordinate. I think this will give the answer.
- Nascent March 10, 2013Approach:
Let D be the distance array.
Let P be the petrol array.
int [] D = {4, 7, 4, 8, 4, 1};
int [] P = {3, 5, 3, 8, 3, 6};
Now start with i=0;
D[0] = 4 > P[0] = 3; i=0 can not be starting point so we move to i=1;
D[1] = 7 > P[1] = 5; i=1 can not be starting point So we move to i=2;
D[2] = 4 > P[2] = 3; i=2 can not be starting pointso we move to i=3;
D[3] = 8 <= P[3] = 8; i=3 can be starting point, now keep on summing the D[i] and P[i] and P[i] >= D[i]
D[4] = 4 > P[4] = 3; here the P[i] is not greater or equal to D[i] so we break; and start from next i=5;
D[5]=1 < P[5] = 6; and carry over petrol is 5
now,
D[0] = 4 < P[0] + carry = 3 + 5;
D[1] = 7 < P[1] + carry = 5 + 4;
D[2] = 4 < P[2] + carry = 3 + 2;
D[3] = 8 < P[3] + carry = 8 + 1;
D[4] = 4 <= P[4] + carry = 3 + 1; // now next i = 5 is the same as the starting point ie index 5.
So the starting point is index=5;
Total time complexity: O(n)
#include<stdio.h>
/* A utility function that prints a given arr[] of length size*/
void printArray(int arr[], int size)
{
for(int i = 0; i < size; i++)
printf("%d ", arr[i]);
printf("\n");
return;
}
/* The core function that recursively generates and prints all sequences of
length k */
void printSequencesRecur(int a[],int arr[], int n, int k, int index)
{
int i;
if (k == 0)
{
printArray(arr, index);
}
if (k > 0)
{
for(i = 0; i<n; ++i)
{
arr[index] = a[i];
printSequencesRecur(a,arr, n, k-1, index+1);
}
}
}
/* A function that uses printSequencesRecur() to prints all sequences
from 1, 1, ..1 to n, n, ..n */
void printSequences(int a[],int n, int k)
{
int *arr = new int[k];
printSequencesRecur(a,arr, n, k, 0);
delete(arr); // free dynamically allocated array
return;
}
/* Driver Program to test above functions */
int main()
{
int a[]={2,8,9,16};
int n = 3;
int k = 2;
printSequences(a,4,k);
getchar();
return 0;
}
We can use a doublylinked list in association with hash map. The map will have key as name i.e "abc","def" etc and the value field will be pointer to the doubly link list node which contains the numerical value. Whenever we delete the the entry will be removed both from the map as well as the doubly linked list. Becoz of the doubly linked list the order will be maintained. All operation can be done in O(1).
- Nascent October 21, 2012After seeing so many comments , I felt that I need to give more details. Consider the array below:
a[ ]={2,8,1,9,10,5,7,11,13}
output={1,2,9,8,5,10,7,11,13}. Here the order of odd and even numbers are same. The one which is more in number will be assembled at last. I hope the qns is now clear.
Convert the tree to sorted doubly linked list. Then follow the same procedure as in case of array.
- Nascent February 12, 2014