Adobe Interview Question for Developer Program Engineers


Country: United States
Interview Type: Written Test




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

apologise examples
0123456789 valid
012345678a invalid
0123a56789 invalid
01234" " valid
012345678" " valid
01234567" " valid
" "12345 invalid
1234" "678 invalid
123" "4" "5678 invalid
in b/w inverted commas we have spaces and each array is of length 10

- rocky September 11, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

Hello Rocky
I forgot the last case
Here's java code again
thx

public static void main(String[] args){
		String a="12345a";
		System.out.println(solve(a));
						
	}	
	
	static boolean solve(String a){
	
		char[] arr = a.toCharArray();
		int tmp=0;
				
		for( int i=0;i<arr.length;i++){
			char c=arr[i];
			tmp=(int)(c-'0');
			if(i!=arr.length-1){
				if(tmp>0 && tmp<10)
					continue;
				else
					return false;	
			}{
				
				if(c==' ' || (tmp>0 && tmp<10))
					continue;
				else
					return false;
			}
			
		}
		return true;			
	}

- Youngsam September 13, 2014 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

public static void main(String[] args){
		String a="1234a56";
		System.out.println(solve(a));
						
	}	
	
	static boolean solve(String a){
	
		char[] arr = a.toCharArray();
		int tmp=0;
		
		for(char c:arr){
			tmp=(int)(c-'0');
			if(tmp>0 && tmp<10)
				continue;
			else
				return false;
		}
		return true;					
	}

- Youngsam September 12, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

youngsam I think your code fail on this test case when we have space at end

01234567" " but that we have to take valid

Test case
0123456789 valid
012345678a invalid
0123a56789 invalid
01234" " valid
012345678" " valid
01234567" " valid
" "12345 invalid
1234" "678 invalid
123" "4" "5678 invalid

- rocky September 12, 2014 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

#include <string.h>
#include <stdio.h>
bool solve(char* c, int len);

int main()
{

char* str = " 12345678";
printf("isnumber:%d\n", solve(str, strlen(str)));
return 1;
}

bool solve(char* c, int len)
{
for (int i=0; i<len; i++)
{
char tmp = c[i]-'0';
if(i!=(len-1))
{
if(tmp<0 || tmp>10)
{
return false;
}
}else if(tmp== ((int)(' ')-'0') || (tmp>=0 && tmp<10))
{
return true;
}
}
return false;
}

- rex September 12, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

bool myFunction(char *a, int len)
{
bool valid = false;
for(int i=0; i<len-1; i++)
{
if(a[0] == ' ')
{
return false;
}

if(a[i] >= '0' && a[i]<= '9')
{
valid = true;
continue;
}
else
{
if(a[i] == ' ' && a[i+1]== '\0')
{
return true;
}
else
{
return false;
}
}
valid = true;
}

return valid;
}

- ashvik.verma September 12, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Returns -1 if invalid and 0 if valid. All spaces is valid, but can be made invalid easily.

int ValidateNumber(string s)
{
    size_t len = s.size();
    int i = 0;
    while(i < len)
    {
        if(s[i] == ' ')
            break;
        if(s[i] >= '0' && s[i] <= '9')
            i++;
    }
    while(i<len)
        if(s[i++] != ' ')
            return -1;
    return 0;
 }

- Anonymous September 12, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

If you're going to use C++ then you might as well use bool. Also, it's easy to correct the all spaces problem. (Which would return a false value) Just track to see if you've ever seen a digit. If you've never seen one before spaces/other characters occured, it's false, otherwise, true - with trailing spaces.

bool ValidateNumber(string s)
{
    size_t len = s.size();
    int i = 0;
    bool hasDigit = false;
    while(i < len)
    {
        if(s[i] == ' ')
            break;
        if(s[i] >= '0' && s[i] <= '9') {
            i++;
            hasDigit = true;
	}
    }
    while(i<len)
        if(s[i++] != ' ')
            return false;
    return hasDigit;
 }

- Sage W September 12, 2014 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

Wont your while loop become infinite if any s[i] is something, other than a space or a digit?

- Luna September 14, 2014 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote
{{{ boolean isValidNum(char num[],int n) { boolean gotspace=false; for(int i=0;i<n;i++) { if(num[i]==' ') { gotspace==true; continue; } if(num[i]>=0 && num[i]<10 && gotspace==false) continue; esle return false; } return true; - Luna September 14, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

public static void main(String[] args) {

System.out.println("Enter the string :\n");
Scanner in = new Scanner(System.in);
String inputString = in.nextLine();
int i = 0;
boolean flag = true;
while (i < inputString.length() - 1) {
if (inputString.charAt(i) == ' ') {
flag = false;
break;
} else if (inputString.charAt(i) >= '0'
&& inputString.charAt(i) <= '9') {
i++;
continue;
} else {
flag = false;
break;
}
}
if (i == inputString.length() - 1) {

if (inputString.charAt(i) == ' '
|| (inputString.charAt(i) >= '0' && inputString.charAt(i) <= '9')) {
flag = true;
} else
flag = false;
}
if (flag == true)
System.out.println("Valid string");
else
System.out.println("invalid string");
}
}

- ashishsinghjss September 14, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

#include <stdio.h>
#include <string.h>
 
int match(char [], char []);
 
int main() {
  char a[100], b[100];
  int position;
 
  printf("Enter some text\n");
  gets(a);
 
  printf("Enter a string to find\n");
  gets(b);
 
  position = match(a, b);
 
  if(position != -1) {
    printf("Found at location %d\n", position + 1);
  }
  else {
    printf("Not found.\n");
  }
 
  return 0;
}
 
int match(char text[], char pattern[]) {
  int c, d, e, text_length, pattern_length, position = -1;
 
  text_length    = strlen(text);
  pattern_length = strlen(pattern);
 
  if (pattern_length > text_length) {
    return -1;
  }
 
  for (c = 0; c <= text_length - pattern_length; c++) {
    position = e = c;
 
    for (d = 0; d < pattern_length; d++) {
      if (pattern[d] == text[e]) {
        e++;
      }
      else {
        break;
      }
    }
    if (d == pattern_length) {
      return position;
    }
  }
 
  return -1;
}

- Harpreet SIngh Saini September 22, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Here's the JAVA code.:

public boolean isValidNumber(char[] str)
	{
		boolean result = true;
		int begin = 0;
		int end = str.length;
		while(begin < end)
		{
			// If current element is a space then
			// all following elements should be spaces.
			if(str[begin]-' '==0)
			{
				for(int i=begin+1;i<end;i++)
				{
					if(str[i]-' '==0)
					{
						continue;
					}
					else
					{
						result = false;
						break;
					}
				}
				break;
			}
			//if current element is a character, 
			//then number is invalid
			else if(str[begin]-'0'<=0 || str[begin]-'0' >=9)
			{
				result = false;
				break;
			}
			//if current element is neither a space, 
			//nor a character then it is a number, carry on the checks further
			else
				begin++;
		}
		return result;
	}

- Harsh Sharma September 22, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

public class CheckNumberinString {


public static void main(String args[]){

String s="012345689a";
int i=0;
for(char a='0';i<s.length();a++,i++){

if(s.charAt(i)==a){
}
else{
System.out.println("not valid");
break;
}

if(i==s.length()-1){

System.out.println("valid");

}
}
}
}

- dadu February 09, 2015 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

#include<iostream.h>
#include<conio.h>
int isValid(char *, int);
int main ()
{
clrscr();

 char *arr[5] = {"92 345 678","92345678  "," 92345678","923a45678","92345678"};


 int j,count;
 for(int i=0; i<5; i++)
 {     j=0;
 			count=0;
 		while(arr[i][j]!=NULL)
      {count++;
      j++;}

 cout<<"size: "<<count<<endl;
 cout <<"check:  "<<isValid(arr[i],count)<<endl<<endl;

 }


getch();
return 0;
}

int isValid(char *arr, int len)
{

      if(arr[0]==' ')
      {
      cout<<"first is space"<<endl;
      return 0;
      }

   	for(int i=0; i<len ;i++)
      {
         if((arr[i]!=' ')&&((arr[i]<48)||(arr[i]>57)))
         {
           cout<<"Not a number"<<endl;
           return 1;
          }
         else if((arr[i]==' ')&& (arr[i+1]!=' ') && (arr[i+1]!=NULL))
              {
               cout<<"space in between "<<endl;
               return 2;
              }
      }
         cout<<"this is awesome!2!!!"<<endl;
         return 10;
}

- Arush Mishra March 12, 2015 | 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