Dee
BAN USER- 0of 0 votes
AnswersWrite a program that takes an arbitrary sentence and abbreviates it by replacing each word with the first letter of the word and the last letter of the word and a number representing the number of characters between the first and last letter. For example, Ford would become F2d. Words are separated by spaces or any other non-alphabetic characters. The program should maintain all non-alphabetic characters in their original form
- Dee in United States| Report Duplicate | Flag | PURGE
Senior Software Development Engineer - 5of 5 votes
AnswersGiven a source string and a destination string write a program to display sequence of strings to travel from source to destination. Rules for traversing:
- Dee in United States
1. You can only change one character at a time
2. Any resulting word has to be a valid word from dictionary
Example: Given source word CAT and destination word DOG , one of the valid sequence would be
CAT -> COT -> DOT -> DOG
Another valid sequence can be
CAT -> COT - > COG -> DOG
One character can change at one time and every resulting word has be a valid word from dictionary| Report Duplicate | Flag | PURGE
Google Site Reliability Engineer - 0of 0 votes
AnswersWrite code using commands below for two rovers to meet. Two rovers are dropped on Mars. Imagine Mars to be a straight infinite plane. When the rovers are dropped on Mars they are dropped with parachute. So their initial position on Mars is on parachute.
- Dee in United States
Only commands possible to execute:
1. Go left
2. go right
3. NO OPERATION
3. If on parachute go to lablel.
Label can be a piece of code with a name where we can transfer execution
Using ONLY commands above write code for rovers to meet.| Report Duplicate | Flag | PURGE
Microsoft - 0of 0 votes
AnswersGiven a set of points A [A1,A2,...,An] in a XY plane and given another point B, find the kth distant point in set A from B. example: 1st point would be the one at a shortest distance from B and so on. We need to find Kth.
- Dee in United States
I gave an alogorithm to calculate the distance of point B from every point in set A and then sort this result and return kth (complexity = O(n) +O(nlogn) (for sort nlogn). But I was asked to improve the complexity.
Can someone please help me with a solution with better complexity.| Report Duplicate | Flag | PURGE
Microsoft Software Engineer / Developer - 0of 0 votes
AnswersImagine you are a contractor who builds houses. Building of every house takes man power. Example: HouseA (manpower to build 20 days, profit when sold = 20K,
- Dee in United States
HouseB manpower to build = 5 days, profit when sold = 11K,
HouseC manpower to build = 5 days and porfit = 10.5K )
Write a function which takes total available manpower as parameter and returns which house building will give max profit.
So for this example if we pass 15 days to the function the answer would be HouseB and HouseC.| Report Duplicate | Flag | PURGE
Microsoft Software Engineer / Developer - 0of 0 votes
AnswersFlatten a binary tree in the its inorder traversal form. Example if there is a tree like
- Dee in United States
01
0203
04050607
Flatten it to 04->02->05->01->06->03->07
Right of 4 should be pointing to 02 and so on.
The order is inorder traversal order
I was asked to use Recursion
PLease can some one post C# code for this.| Report Duplicate | Flag | PURGE
Microsoft Software Engineer / Developer Trees and Graphs - 0of 0 votes
AnswersGiven a string "abcd" print combinations of length n. Example if n= 3 print abc, abd, acd, bcd. Was asked to use recursion. Can someone please help me with a C# recursive function for this.
- Dee in United States| Report Duplicate | Flag | PURGE
Microsoft Software Engineer / Developer - 0of 0 votes
AnswersGiven a string, evaluate the aithmetic expression that it represents . Example return 1 int for string 1+2-10/5
- Dee in United States| Report Duplicate | Flag | PURGE
6
2 9
1 7 3 11
This tree cannot be a BST. For a tree to be a BST, every node to the left of root should be smaller than the root and every node to the right of root should be greater than the root. In this case, 7 cannot be on the left of 6. And 3 cannot be on the right.
in order to validate if a tree is BST we will have to make sure all nodes are traversed. How can we say for sure a tree is BST w/o traversing all nodes ?
Plus calculating min and max values is done by function itself.....the call from main can pass -infinity as min value and +infinity as max value (or int.min and int.max)
Using recursion it can be done as follows:
public static Tree InorderSuccessor(int value, Tree root, ref Tree caller, ref Tree successor)
{
if (root != null)
{
InorderSuccessor(value,root.Left, ref root, ref successor);
if (root.Data == value)
successor = caller;
InorderSuccessor(value, root.Right, ref root, ref successor);
}
return successor;
}
So the idea is to traverse the tree in in-order format. The caller of the function will always be the successor.
When you call from main the call will look like this
Tree succ = null;
int value; assing this to the value of node for which you need the successor for.
succ = InorderSuccessor(value,root, ref succ, ref succ);
Woody,
- Dee November 24, 2013Thanks. But I have couple of questions:
1. if there is a word "1234" then looks like you will completely skip it, coz u r checking for isLetter in abvBg and abvEnd
2. the non alphabetic characters in string should stay as it is. I see you r skipping them all together.