Adobe Interview Question for Software Engineer / Developers






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

void PrintFrogPath(int a[], int length, int aCount,  int path[], int bCount)
{
	if(aCount == length && path[bCount-1] == a[aCount-1])
	{
		for(int i = 0 ; i < bCount ; i++)
			cout<<path[i]<<" ";
		cout<<endl;
		return;
	}
	else if(aCount < length)
	{
		for(int i = 1; i<=2 ; i++)
		{
			path[bCount] = a[aCount];
			PrintFrogPath(a, length, aCount+i, path, bCount+1);
		}
	}
}
void main()
{
	int c[] = {1,2,3,4};
	int d[] = {0,0,0,0};
	PrintFrogPath(c,4,0,d,0);
}

- Paras March 19, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

hi Paras, can Explain The Algorithm & Logic Behind The code..

Plz Explain The Logic ..Hope You Will Res[pond me ASAP.

Waiting For Your Explainable

- Algoseekar April 04, 2011 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

this seems the cleanest code

- novice May 11, 2011 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

int HasConsecutiveZeroes(n)
{

int flag = 0;

while(n)
{
int z = n & 0x1;

if(z == 0)
if(flag)
return 1;
else
flag = 1;
n = n >> 1;
}
return 0;

}

print(a, n , p)
{

int i = 1, num = 0 ;

int pos, z;
int j = 1;
while( j < p)
{
if(HasConsecutiveZeroes(j))
{
j++;
continue;
}

z = j;

path[num] = a[0];
num++;

while(z)
{
if(z & 0x01)
{
path[num] = a[i + pos];
pos++;
num++;
}
z = z >> 1;
}
path[num] = a[n-1];
for(int q = 0 q < num ; q++)
cout<<path[q];
num = 0;
j++;
}

}

void printPaths(int a[], int n)
{

int p = n - 2;

p = pow(2, p); // for generating all possible combinations...

print(a, n , p - 1);

}
int main()
{

int a[] = { 0 , 1, 2 ,3, 4 };

int n = 5;

printPaths(a, n);

}

- Nit March 19, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Frog can take a leap of 1 or 2 at any time therefore if number of rock is N then total number of paths will be Nth Fibonacci number. Below is the code to print all the paths:

void printFrogLeap (int* pArray, int num, int count)
{
	if(count > num)
	{
		return;
	}
	if(count == num)
	{
		int i;
		if(pArray[count-1] == 1) /*path is complete or not*/
		{
			for (i=0; i < num; i++)
			{
				if (pArray[i] == 1)
				{
					printf ("[%d]", i+1);
				}
			}
			printf ("\n");
		}
		return;
	}
	pArray [count] = 1;
	printFrogLeap (pArray, num, count+1);
	if(count+1 < num)
	{
		pArray [count+1] = 0;/*exclude this entry from path, since its used*/
	}
	printFrogLeap (pArray, num, count+2);
	if(count+2 < num)
	{
		pArray [count+2] = 0;/*exclude this entry from path, since its used*/
	}	
}


int main ()
{
	int *array, num;
	printf ("Enter num of rocks: ");
	scanf ("%d", &num);
	array = (int*)malloc (sizeof(int)*num);
	memset (array,0x00,num);
	printf ("Total paths: \n");
	printFrogLeap (array, num, 0);
	free (array);
	return 0;
}

- Tulley March 19, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

hi Paras, can Explain The Algorithm & Logic Behind The code..

Plz Explain The Logic ..Hope You Will Respond me ASAP.

Waiting For Your Explainable

- Algoseekar April 04, 2011 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

hi tully, can Explain The Algorithm & Logic Behind The code..

Plz Explain The Logic ..Hope You Will Res[pond me ASAP.

Waiting For Your Explainable

- Algoseekar April 04, 2011 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

@Algoseekar:
As I wrote above that total number of path will be Nth Fibonacci number. If u trace the recursion (trace the variable "count") u can easily find how its printing the path.
e.g.
if N=5
count=0, pArray[0]=1, call with count=count+1 (=1)
.......
count=4,pArray[4]=1,all with count=count+1 (=5)
print path and return.
Now call'll take place with count=6 and it'll return at line 5. So, for count=4 both call finished. Now the execution will take place for count=3 from line 25. So on..
I think this will help.

- Tulley April 04, 2011 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

@tulley..thnx..man the way u coded it brilliantly... I am able to understand it now & getting felling of this approach .it seems to be me aslo Fibonacci ..i will appriciate if u will through some more light on these two line

if(count+1 < num)
{
pArray [count+1] = 0;/*exclude this entry from path, since its used*/
}
printFrogLeap (pArray, num, count+2);
if(count+2 < num)
{
pArray [count+2] = 0;/*exclude this entry from path, since its used*/
}

Thanks & keep it up..this work

- Algoseekar April 04, 2011 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

1. the if check is to avoid array over-bound. This if check is not required if u take array of size N+2 (i have taken it as N).
2. When these lines will get executed we have already printed the path("i" at line number 14), so in next call we dont want to print it thats y again making it to 0.

- Tulley April 05, 2011 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

void print_path(vector<int> path) {
for(int i = 0; i < path.size(); i++) {
printf("%d,", path[i]);
}
printf("\n");
}

void paths(int rocks_left, int total_rocks, vector<int> path) {
if(rocks_left == 0) {
print_path(path);
return;
}
path.push_back(total_rocks - rocks_left + 1);
paths(rocks_left - 1, total_rocks, path);
if(rocks_left > 2) paths(rocks_left - 2, total_rocks, path);
}

int main(int argc, char **argv) {
int rocks = 5;
vector<int> vec;
paths(5,5,vec);
return 0;
}

- jay March 19, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

public static void frogLeap(int N) {
        frogLeap(N, N, new StringBuilder());
    }

    public static void frogLeap(int N, int M, StringBuilder sb) {
        if (N == 0) {
            System.out.println(sb.toString());
            return;
        }
        if (N == 1) {
            System.out.println(sb.toString() + M);
            return;
        }
        final int len = sb.length();
        sb.append("" + (M - (N - 1)));
        frogLeap(N - 1, M, sb);
        sb.setLength(len);
        if (N != M) {
            sb.append("" + (M - (N - 2)));
            frogLeap(N - 2, M, sb);
            sb.setLength(len);
        }
    }

- gngr44 March 20, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

import java.util.*;

public class FrogAcrossRiver {
public static void jump(int n){
jump(0, n, new Stack<Integer>());
}

private static void jump(int from, int dest, Stack<Integer> route){
if(from == dest){
p(route);
return;
}
route.push(from + 1);
jump(from + 1, dest, route);
route.pop();
if(from != 0 && from <= dest - 2){
route.push(from + 2);
jump(from + 2, dest, route);
route.pop();
}
}

private static void p(Stack<Integer> route){
for (int i = 0; i < route.size() - 1; i++){
System.out.print(route.get(i)+ ", ");
}
System.out.print(route.peek() + "\n");
}

public static void main(String[] args){
jump(7);
}
}

- Anonymous March 21, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

void printVector(vector<char>& array)
{
for(int i=0; i<array.size(); i++)
{
cout << array[i] + '0' ;
}
cout << endl;
}

void leapFrog(int i, int n, vector<char>& array)
{
if(i == n)
{
array.push_back(i - '0');
printVector(array);
array.pop_back();
return;
}
else if(i == n-1)
{
array.push_back(i - '0');
leapFrog(i+1, n, array);
array.pop_back();
}
else
{
array.push_back(i - '0');
leapFrog(i+1, n, array);
leapFrog(i+2, n, array);
array.pop_back();
}
}

- www.asif.com March 21, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

{{
//Jeff
#include <iostream>
#include <string>
#include <sstream>
#define SIZE 6


using namespace std;



int stones[]={1,2,3,4,5,6};
void hopAcross(int location,string path,bool jumped);

int main(int argc,char** argv)
{
ostringstream path;
path<<stones[0];
hopAcross(1,path.str(),0);

}
void hopAcross(int location,string path,bool jumped)
{
if(location==SIZE)
{
cout<<path<<endl;
return;
}
//produce jump tree
if(jumped==false && location+1<SIZE)
{
hopAcross(location+1,path,true);
}
ostringstream temp;
temp<<path<<"-->"<<stones[location];
hopAcross(++location,temp.str(),false);
}
}}

- Jeff March 21, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

string int2string(int data){
       ostringstream buffer;
       buffer<<data;
       return buffer.str();
       }
void printFrogPath(int rl,int tr, string s){
     if(!rl)
     {
            cout<<s<<endl;
            return;
     }
     s += int2string(tr-rl+1);
     printFrogPath(rl-1,tr,s);
     if(rl>2)
     printFrogPath(rl-2,tr,s);
}       

printFrogPath(4,4,"");

- RD March 21, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

#include<iostream>
#include<string>
using namespace std;

void paths(int);
void paths(int,int,bool,string);

int main()
{
	int num_stones=0;
	cout<<"Number of stones:";
	cin>>num_stones;
	paths(num_stones);
	return 0;
}

void paths(int num)
{
	string path="1";
	paths(num,1,false,path);
}

void paths(int max,int curr,bool skipped,string path)
{
	if(curr==max)
	{
		cout<<path<<endl;
	}
	else
	{
		paths(max,curr+1,false,path+','+(char)('0'+curr+1));
		if(!skipped && curr+1<max)
		{
			paths(max,curr+2,true,path+','+(char)('0'+curr+2));
		}
	}
}

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

Sorry posted previous solution before testing...

#include<iostream>
#include<string>
using namespace std;

void paths(int,int,string);

int main()
{
	int num_stones=0;
	cout<<"Number of stones:";
	cin>>num_stones;
	paths(num_stones,1,"1");
	return 0;
}

void paths(int max,int curr,string path)
{
	if(curr==max)
	{
		cout<<path<<endl;
	}
	else
	{
		paths(max,curr+1,path+','+(char)('0'+curr+1));
		if(curr+1<max)
		{
			paths(max,curr+2,path+','+(char)('0'+curr+2));
		}
	}
}

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

Following is the code to generate the frog path generically(means for ne number of stone) and recursively...I havnt run the code in the complier(it may not be complete syntax compliant)...just wrote and think that it will work fine..Do tell me if there are ne issues..


Following is the concept...
Take the array as 1 1 1 1 1 as for five stones each initially represents '1'...here 1 represents that frog doesnt skip that particular stone..

and if it is 1 1 0 1 1 ..then it skips the 3rd one..
Take the following array to pass into array

a[]=[1, 1 , 1 , 1 ,1] for five stones
so call the following function-- printPathsForFrog(a,1)

printPathsForFrog(int a[],int counter)
{
for(int i=0;i<a.length;i++)
{
if(a[i]==1)
{
printf(i+1);
}
}
for(int j=counter;j<a.length-1;j++)
{
if(a[j-1]==1)
{
a[j]=0;
printPathsForFrog(a,counter++);
a[j]=1;
}
else
{
j++;
}
}

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

#include<stdio.h>
#define max 20
int n;
void perm(int *p,int index,int i)
{int j;
if(i==n)
{ p[index]=i;
for(j=1;j<=index;j++)
printf("%d ",p[j]);
printf("\n");
}
else
{ p[index]=i;
if(i<n-1)
perm(p,index+1,i+2);
if(i<n)
perm(p,index+1,i+1);
}
}

main()
{
int p[max];
printf("\n Enter no of Rocks :");
scanf("%d",&n);
printf("\n For %d to %d rocks possible paths:\n",1,n);
perm(p,1,1);
}

- SachinGuptaMNNIT June 17, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

#include<stdio.h>
#define max 20
int n;
void perm(int *p,int index,int i)
{int j;
if(i==n)
{ p[index]=i;
for(j=1;j<=index;j++)
printf("%d ",p[j]);
printf("\n");
}
else
{ p[index]=i;
if(i<n-1)
perm(p,index+1,i+2);
if(i<n)
perm(p,index+1,i+1);
}
}

main()
{
int p[max];
printf("\n Enter no of Rocks :");
scanf("%d",&n);
printf("\n For %d to %d rocks possible paths:\n",1,n);
perm(p,1,1);
}

- SachinGuptaMNNIT June 17, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Apologies if CODE/Logic was presented already. Thanks

package algorithms;

import java.util.ArrayList;
import java.util.List;

import javax.print.PrintService;

public class FrogRiverCrossing {
	
	public static void main(String[] args) {
		
		int n=5;
		
		List<String> finalList=printSteps(n);
		
		for(int i=0;i<finalList.size();i++){
			System.out.println(finalList.get(i));
		}
	}
	
public static List<String> printSteps(int n){
	
	if(n==1){
		return new ArrayList<String>(){{add("1");}};
	}
	if(n==2){
		return new ArrayList<String>(){{add("1-2");}};
	}
	
	List<String> listMinusOne=printSteps(n-1);
	List<String> listMinusTwo=printSteps(n-2);
	List<String> nList=new ArrayList<String>();
	
	for(int i=0;i<listMinusOne.size();i++){
		nList.add(listMinusOne.get(i)+"-"+n);
	}
	for(int i=0;i<listMinusTwo.size();i++){
		nList.add(listMinusTwo.get(i)+"-"+n);
	}
	
	return nList;
}

}

- Ivar July 20, 2011 | 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