Adobe Interview Question for Software Engineer / Developers






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

Can you please explain the problem little bit. Thanks.

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

Yse Ternary Operator

bool BinSearch(int arr[], int elem, int left, int right)
{
int mid = (left+right)/2;

if (arr[mid]== elem)
{
printf("Element found at [%d] Position", mid);
} else {
(arr[mid]>elem)?BinSearch(arr, elem, left, mid):BinSearch(BinSearch(arr, elem, mid+1, right));
}

printf("Element Not Found");

}

- Kandukurees March 17, 2009 | Flag Reply
Comment hidden because of low score. Click to expand.
1
of 1 vote

How is using a ternary operator different from using if-then-else?

- T March 17, 2009 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

I don't know why people try to ask micro-code optimization questions in interviews.

Anyway, here is one approach

// Calculates 'positiveness' of given integer
// Returns 1 is x > 0, and 0 if x < 0.
// Assume 32 bit integer and left most bit is sign bit.
// x = 0 is invalid input.

int Positivity(int x) {
    return -(x & (0x80000000));
}

bool BinarySearch(int [] arr, int key, int left, int right) {
    
    int mid = (left+right)/2;
    
    if (arr[mid] == key) {
        return true;
    }
    
    int posit = Positivity(key - arr[mid]);

    int newLeft = mid*posit + (1-posit)*left;
    int newRight = right*posit + (1-posit)*mid;
    
    return BinarySearch(arr, key, newLeft, newRight);

}

// There might be bugs, but you get the idea.

- T March 17, 2009 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

int Positivity(int x) {
return -(x & (0x80000000));
}

The above Code does not work.
Could you help me address this issue

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

int Positivity(int x) { return (~(x & (0x80000000)))>>31;}

- Thinking March 27, 2009 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

What the function will return in case the number is not present in the array.

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

You should be able to fix it yourself, if you actually have the written the code and can debug it.

The idea is to get the sign bit and use that. The current code assume 32 bit integers and yes, it is not portable.

Perhaps you can fix the code and post it here...

The original question is a bit silly, anyway.

- T March 22, 2009 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

The goal as I understand is to avoid 2 comparisons and maker only one.
Lets say n is 'your' number and k is the key.
Normally, we'd check: n < k => go left; n > k => go right.

Instead, just check mod(n-k) > 0 => go right; else go left.

- Just use this June 04, 2009 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

do you still think the above approach makes sense?

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

I thinks it perfectly make sense ... we are not making the compiler compare the numbers twice .... we are checking the it against a value now and the comparison will be done once only.
Please let me know if you still think there is something wrong here.

- Tarunjit Singh May 25, 2012 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

it does make sense but we need to check 2 conditions ....

- toTERUNJIT April 25, 2014 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

low = 0
high = N
while (low < high) {
mid = low + ((high - low) / 2) // Note: not (low + high) / 2 !!
if (A[mid] < value)
low = mid + 1;
else
//can't be high = mid-1: here A[mid] >= value,
//so high can't be < mid if A[mid] == value
high = mid;
}
// high == low, using high or low depends on taste
if ((low < N) && (A[low] == value))
return low // found
else
return -1 // not found

- AB June 22, 2009 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

nice.. this pushes the comparison of equality to outside loop though.

- Amit Priyadarshi October 01, 2010 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

mid = low + ((high - low) / 2) // Note: not (low + high) / 2 !!
"note", wow before making that extraordinary comment, epand dat dude its equal to (low + high) / 2.
its still the same approach!

- tricky mads August 24, 2012 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

LOLzzz

- shubham April 25, 2014 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

int BinSrch(int *array,int n){    
                int low=0,high=n-1;
  		while (low < high) {
                  mid = (low + high) / 2;
                  if (key > array[mid])
                        low = mid + 1;
                  else
                        high = mid; 
                }
                /* here low == high */
	        if (low < n && array[low] == key)
		  return 1;         /* search_key found at low */
	        else return 0;
             }

- Rockstar August 08, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

Plz say if dis is correct...

- Rockstar August 08, 2010 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

why we need to check low<n in
"if (low < n && array[low] == key)"

low will be always <n in any case ??

- ridercoder October 22, 2010 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

This can be done by comparing only a single time as described below :-
Pseudo code :-

int bSearch(int nArray[], int nLength, int nVal)
//

int nRes <- -1
int nStart <- 0
int nEnd <- nLength - 1
while nStart <= nEnd
do
- int nMid <- (nStart + nEnd) / 2
- if nVal > nArray[nMid]
- then
- - nEnd <- nMid - 1
- else
- - nRes <- nMid
- - nStart <- nMid + 1

return nRes

- sid1505 September 06, 2015 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

function _binarySearch2(arr, start, end, val) {
	if (start === end)
		if (arr[start] === val)
			return start;
		else
			return -1;

	const mid = parseInt((start + end) / 2);

	if (val > arr[mid])
		return _binarySearch2(arr, mid + 1, end, val);
	else
		return _binarySearch2(arr, start, mid, val);
}

function binarySearch2(arr, val) {
	if (!arr.length)
		return -1;

	return _binarySearch2(arr, 0, arr.length - 1, val);
}

const arr = [4, 5, 7, 8];

console.log(binarySearch2(arr, 7));

- sid July 08, 2018 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

function _binarySearch2(arr, start, end, val) {
	if (start === end)
		if (arr[start] === val)
			return start;
		else
			return -1;

	const mid = parseInt((start + end) / 2);

	if (val > arr[mid])
		return _binarySearch2(arr, mid + 1, end, val);
	else
		return _binarySearch2(arr, start, mid, val);
}

function binarySearch2(arr, val) {
	if (!arr.length)
		return -1;

	return _binarySearch2(arr, 0, arr.length - 1, val);
}

const arr = [4, 5, 7, 8];

console.log(binarySearch2(arr, 7));

- Anonymous July 08, 2018 | 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