Epic Systems Interview Question






Comment hidden because of low score. Click to expand.
0
of 0 vote

As it is most obvious, the data structure to be used in this scenario is the STACK.
Here's the pseudocode:

check the first bit in the current position.
          if 1, top=top-2(delete current byte and subsequent byte)
          else top=top-1(delete only current byte)

- nagu89 September 20, 2009 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

But we need to delete the char BEFORE the index, right?

- chao October 07, 2009 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

Looking at the start of current index you can't be sure if the last char is a kanji char or ascii char, For that you need to be sure about the first char of the array.

so if the first char is Kanji (1@ MSB)or ascii, u need to increment the index accordingly.

- skp September 20, 2009 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

A small mistake in my above algorithm..
the first bit of the previous index should be checked.
The rest works out well

- nagu89 September 23, 2009 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

All you need to do is check the msb at index-2. Assuming valid input, if MSB@index-2 is 1,then the prev character is kanji.. otherwise its ascii

int backspacePos(int index, char*arr)
{
if(index==0 ||index==1) return 0;
if(arr[index-2]&0x10000000==0x10000000)
return index-2;
return index-1;
}

char* shiftArr(int index1, int index2, char *arr)
{
int t1=index1,t2=index2;
while(arr[t2]!='\0')
{
arr[t1]=arr[t2];
t1++;
t2++;
}
arr[t1]='\0';
return arr
}

//usage
//k=backspacePos(index,array)
//array=shiftArr(k,index,array);

- NishanthC September 26, 2009 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

you are forgetting that its a combination of both ascii and kanji

- Anonymous November 03, 2009 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

he's generally correct, arr[index-2]&0x10000000==0x10000000 is true if a char in arr is kanji char.

but 10000000 should be binary, rather than 0x, right?

- beyondfalcon November 27, 2009 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

Does doing backspace simply imply shifting characters that begin from the index in the array one position earlier? Isnt it too much of overhead? I am not sure what exactly is expected here.

- John October 16, 2009 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Why we have such algorithm problem? Is it appear in on-site interview?

- Anonymous October 24, 2009 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Can anyone plz bring out the correct solution for this, so that we don't get confused?

- Shashank November 01, 2009 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

first a few things to note-
--- i am assuming the data is stored as big endian. if it were stored as little endian, it would actually be easier for us to decode. little endian means if the data in hex is - 0xABCD, in the memory it is stored as CD AB. so for Kanji I would check if 0xCD & 0x80 == 1. since I am assuming big endian just for fun, by byte ordering is like AB CD.
--- how do I get the CD byte from the given index.
strncpy(a,&array[index-1],2); //so this will copy 2 bytes from the required position, which is one less than the given position.

if(a[1]&0x80==0x80) we know it was a kanji character, else fro ASCII we need to make sure a[0]& 0x80 == 0, because the MSB for that byte needs to be 0 for it to be an ASCII .

once we have figured out which character it was, it is easy to delete either one byte (ascii) or 2 bytes(kanji) from the original array.
now the original index numbers will be affected and I do not know whether they want us to fix that too.

---

- bhaskar December 04, 2009 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

a[1]&0x80==0x80

In the question it is mentioned that the MSB =1, the other bits can be anything, your statement will mostly be false expect if a[1]==0x80

- Anonymous December 07, 2009 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

Assuming BigEndian

void backSpace (char* text, int index)
{
	if (index <= 0 || index > strlen(text)-1)
	{
		return;
	}

	int shift = (text[index-2] & 0x80) ? 2 : 1;
	
	while (text[index] != '\0')
	{
		text[index-shift] = text[index];
		index++;
	}
	text[index-shift] = '\0';
}

- Andy December 17, 2009 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Hey Andy can you explain:
int shift = (text[index-2] & 0x80) ? 2 : 1;

If say text[index-2] = 0xCD, then you are checking:
if (11001101 & 10000000) == true, i.e. 11111111
then shift = 2
else shift = 1

But if condition will always be false then ?

- Anonymous February 14, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

What is the question here? Can anyone post please!

- Finding the question April 06, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

I Hope this was the original question..

First some definitions for this problem: a) An ASCII character is one byte long and the most significant bit in the byte is always ‘0′. b) A Kanji character is two bytes long. The only characteristic of a Kanji character is that in its first byte the most significant bit is ‘1′.

Now you are given an array of a characters (both ASCII and Kanji) and, an index into the array. The index points to the start of some character. Now you need to write a function to do a backspace (i.e. delete the character before the given index).

- Anonymous April 23, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

hi cunomad,

you are such a lose.fuck you man.fuck off from Careercup.Why are you writing random questions and waste people time.Dont play with our lifes and careers.You loser.Go to hell dude..Please die

- @cunomad August 22, 2010 | Flag Reply


Add a Comment
Name:

Writing Code? Surround your code with {{{ and }}} to preserve whitespace.

Books

is a comprehensive book on getting a job at a top tech company, while focuses on dev interviews and does this for PMs.

Learn More

Videos

CareerCup's interview videos give you a real-life look at technical interviews. In these unscripted videos, watch how other candidates handle tough questions and how the interviewer thinks about their performance.

Learn More

Resume Review

Most engineers make critical mistakes on their resumes -- we can fix your resume with our custom resume review service. And, we use fellow engineers as our resume reviewers, so you can be sure that we "get" what you're saying.

Learn More

Mock Interviews

Our Mock Interviews will be conducted "in character" just like a real interview, and can focus on whatever topics you want. All our interviewers have worked for Microsoft, Google or Amazon, you know you'll get a true-to-life experience.

Learn More