yasharonline
BAN USER
- 1of 1 vote
AnswersPrint elements of a matrix in spiral form.
- yasharonline in United States for Azure| Report Duplicate | Flag | PURGE
Microsoft SDE1 Matrix - 0of 0 votes
AnswersIt was an over email interview:
- yasharonline in United States
Write a program that takes as input a sufficiently large text document (several are available online for testing; e.g. via Project Gutenberg), and produces as output (via stdout) an alphabetical listing of each unique word in the document (case insensitive and space separated, though be careful to consider hyphenated words), along with the lines from the input document that the word appears on. Each unique word (and the list of lines that it appears on) should be on a separate line in the output.
For example, taking the following text as input:
This is
some kind OF text it
Is an example of text
The following would be the output:
an 3
example 3
is 1 3
it 2
kind 2
of 2 3
some 2
text 2 3
this 1| Report Duplicate | Flag | PURGE
Apkudo SDE1 Sorting
Recursive C# code for this question.
Explanation on comments in-line.
static bool Search(int num, int[,]matrix,int m,int n) //m: number of rows, n: number of columns
{
if (num < matrix[0, 0] || num > matrix[m - 1, n - 1]) return false;
return SearchUtil(num, matrix,0, m, 0, n);
}
static bool SearchUtil(int num, int[,]matrix,int minI,int maxI, int minJ,int maxJ)
{
while (minI<=maxI)
{
int midI = (minI + maxI) / 2;
int midJ = (minJ + maxJ) / 2;
if (matrix[midI, midJ] == num)
return true;
if (num > matrix[midI, midJ]) //If the number is greater than the middle element, it's either on the same row on middle's right side, or the next rows anywere.
{
if (num <= matrix[midI, maxJ - 1]) //if it's smaller or equal to the largest element in this row;
{
return SearchUtil(num, matrix, midI, midI, midJ, maxJ); //it's on the same row, to the right of the middle element.
}
else //if it's bigger than the middle element;
{
return SearchUtil(num, matrix, midI + 1, maxI, 0, maxJ); //it's for sure on one of the next rows.
}
}
if (num < matrix[midI, midJ]) //If the number is smaller than the middle element, it's either on the same row on middle's left side, or the previous rows anywere.
{
if (num >= matrix[midI, 0]) //if it's greater or equal to the smallest element in this row;
{
return SearchUtil(num, matrix, midI, midI, 0, midJ); //it's on the same row, to the left of the middle element.
}
else
{
return SearchUtil(num, matrix, 0, midI - 1, 0, maxJ); //it's for sure on one of the previous rows.
}
}
}
return false;
}
Can you please explain more/provide examples?
- yasharonline January 12, 2017Id did it with a min heap. I don't know how efficient it was but worked and they liked it!
I created a 'Word' class which store 'string word' and 'List<int> line_numbers'.
Please let me know your ideas and make sure to pay attention to the constraint 'Large Text File'.
Repsharonpkarr, None at BT
Hi! My name is Mary. I am a writer for a variety of web and multi-platform applications.I am a ...
RepAlmaRJude, Quality Assurance Engineer at Brocade
I am Alma from Livermore USA, I also enjoy reading – my favourite topics being social history, the development and use ...
Repamandaben422, Graphics Programmer at Abs india pvt. ltd.
Hi, I am a webmaster from the USA. I think social networks have the power to connect two different people ...
Repamysamson688, Accountant
Hi, I am an art teacher, good in all areas of art history, from ancient art through to contemporary art ...
Rephinescarol45, +27655765355 SSD MONEY CLEANING CHEMICAL +27655765355 BLACK MONEY IN JOHANNESBURG, OMAN, SAUDI ARABIA, SUDAN, Somalia ,Zimbabwe Botswana at 247quickbookshelp
I am Carol From San Diego USA, I am Working as a Personal assistant in a Castle Realty organization, I ...
Repjoycepwise, Blockchain Developer at Accenture
Hello, I’m Joyce. I’m a business developer living in Tampa, FL. I am a fan of music, travel ...
- yasharonline June 06, 2017