Adobe Interview Question for SDE1s


Country: India




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

// ZoomBA
def classify( string ){
   // please do some menial work and list all consonants, to ensure that 
   // we do not false miss stuff not in [a-z]
   // =~ is the matches operator 
   if ( string =~ '.*[^aeiou]{5,}.*|.*[aeiou]{3,}.*' ) return 'bad'
   if ( string =~ '.*[\?aeiou]{3,}.*|.*(\?|[^aeiou]){5,}.*' ) return 'mixed'
   return 'good'
}

This is very lazy, using regex, and bad matching on them. But generally gives you the idea.
The fall back *order* is essential.

- NoOne October 12, 2016 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

/**
* Created by kr.abhishek on 10/12/2016.
*/


import java.util.Arrays;
import java.util.Scanner;

public class ArrayTest {

public static void main (String [] args)
{
int a[][] = {{1,92,43,4,5},{234,341,56}};
int b=a.length;
for (int i=0;i<a.length; i++)
{
Arrays.sort(a[i]);
for (int j=0;j<a[i].length;j++)
{
System.out.println(a[i][j]);
}
}
System.out.println("value of legth of a is:"+b);

Scanner scanner = new Scanner(System.in);

System.out.println("enter any string to know its type or enter Q to quit");

String str=null;

do {
str = scanner.nextLine();
System.out.println("the string "+str+"type is "+ stringtest(str));
}
while (!"Q".equals(str));

}


public static String stringtest(String s)
{
int vowelcnt=0;
int conscnt=0;
int qvcnt =0;
int qccnt=0;
String strtype;

for(int i=0;i<s.length();i++) {
if (checkvowel(s.charAt(i)) && s.charAt(i) != '?') {
vowelcnt++;
conscnt = 0;
if (vowelcnt == 3)
break;
}

if (checkconsonant(s.charAt(i)) && s.charAt(i) != '?') {
conscnt++;
vowelcnt = 0;

if (conscnt == 5)
break;
}

if (s.charAt(i) == '?') {
if (vowelcnt == 0 && conscnt == 0) {
while (s.charAt(++i) == '?' && i < s.length() - 1) {
System.out.println("inside while");
}
System.out.println("value of i at exit:" + i);
if (i >= 2) {
return "Mixed";
}
if (checkconsonant(s.charAt(i))) {
qccnt++;
conscnt++;
}
if (checkvowel(s.charAt(i))) {
qvcnt++;
vowelcnt++;
}
}

if (vowelcnt > 0) {
qvcnt++;
vowelcnt++;
if (i < s.length() - 1) {
i++;
if (checkvowel(s.charAt(i))||s.charAt(i)=='?') {
qvcnt++;
vowelcnt++;
}
if (checkconsonant(s.charAt(i))) {
qccnt++;
conscnt++;
}

}
}

if (conscnt > 0) {
qccnt++;
conscnt++;
if (i < s.length() - 1) {
i++;
if (checkconsonant(s.charAt(i))||s.charAt(i)=='?') {
qccnt++;
conscnt++;
}
if (checkvowel(s.charAt(i))) {
qvcnt++;
vowelcnt++;
}

}
}

}
if (conscnt == 5) {
if (qccnt > 0)
strtype = "MIxed";
else
strtype = "Bad";
return strtype;
}

if (vowelcnt == 3) {
if (qvcnt > 0)
strtype = "MIxed";
else
strtype = "Bad";
return strtype;
}
}

strtype="Good";

return strtype;}



public static boolean checkvowel(char c)
{
return (c=='a'||c=='e'||c=='i'||c=='o'||c=='u');
}

public static boolean checkconsonant(char c)
{
return (c=='b'||c=='c'||c=='d'||c=='f'||c=='g'||c=='h'||c=='j'||c=='k'||c=='l'||c=='m'||c=='n'||c=='p'||c=='q'||c=='r'||c=='s'||c=='t'||c=='v'||c=='w'||c=='x'||c=='y'||c=='z');
}
}

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

/**
 * Created by kr.abhishek on 10/12/2016.
 */


import java.util.Arrays;
import java.util.Scanner;

public class ArrayTest {

    public static void main (String [] args)
    {
        int a[][] = {{1,92,43,4,5},{234,341,56}};
        int b=a.length;
        for (int i=0;i<a.length; i++)
        {
            Arrays.sort(a[i]);
            for (int j=0;j<a[i].length;j++)
            {
                System.out.println(a[i][j]);
            }
        }
        System.out.println("value of legth of a is:"+b);

       Scanner scanner = new Scanner(System.in);

        System.out.println("enter any string to know its type or enter Q to quit");

        String str=null;

        do {
           str = scanner.nextLine();
            System.out.println("the string "+str+"type is "+ stringtest(str));
       }
        while (!"Q".equals(str));

    }


    public static String stringtest(String s)
    {
        int vowelcnt=0;
        int conscnt=0;
         int qvcnt =0;
         int qccnt=0;
         String strtype;

        for(int i=0;i<s.length();i++) {
            if (checkvowel(s.charAt(i)) && s.charAt(i) != '?') {
                vowelcnt++;
                conscnt = 0;
                if (vowelcnt == 3)
                    break;
            }

            if (checkconsonant(s.charAt(i)) && s.charAt(i) != '?') {
                conscnt++;
                vowelcnt = 0;

                if (conscnt == 5)
                    break;
            }

            if (s.charAt(i) == '?') {
                if (vowelcnt == 0 && conscnt == 0) {
                    while (s.charAt(++i) == '?' && i < s.length() - 1) {
                        System.out.println("inside while");
                    }
                    System.out.println("value of i at exit:" + i);
                    if (i >= 2) {
                        return "Mixed";
                    }
                    if (checkconsonant(s.charAt(i))) {
                        qccnt++;
                        conscnt++;
                    }
                    if (checkvowel(s.charAt(i))) {
                        qvcnt++;
                        vowelcnt++;
                    }
                }

                if (vowelcnt > 0) {
                     qvcnt++;
                    vowelcnt++;
                    if (i < s.length() - 1) {
                        i++;
                        if (checkvowel(s.charAt(i))||s.charAt(i)=='?') {
                            qvcnt++;
                            vowelcnt++;
                        }
                        if (checkconsonant(s.charAt(i))) {
                            qccnt++;
                            conscnt++;
                        }

                    }
                }

                if (conscnt > 0) {
                    qccnt++;
                    conscnt++;
                    if (i < s.length() - 1) {
                        i++;
                        if (checkconsonant(s.charAt(i))||s.charAt(i)=='?') {
                            qccnt++;
                            conscnt++;
                        }
                        if (checkvowel(s.charAt(i))) {
                            qvcnt++;
                            vowelcnt++;
                        }

                    }
                }

            }
            if (conscnt == 5) {
                if (qccnt > 0)
                    strtype = "MIxed";
                else
                    strtype = "Bad";
                return strtype;
            }

            if (vowelcnt == 3) {
                if (qvcnt > 0)
                    strtype = "MIxed";
                else
                    strtype = "Bad";
                return strtype;
            }
        }

        strtype="Good";

        return strtype;}



    public static boolean  checkvowel(char c)
    {
        return (c=='a'||c=='e'||c=='i'||c=='o'||c=='u');
    }

    public static boolean  checkconsonant(char c)
    {
        return (c=='b'||c=='c'||c=='d'||c=='f'||c=='g'||c=='h'||c=='j'||c=='k'||c=='l'||c=='m'||c=='n'||c=='p'||c=='q'||c=='r'||c=='s'||c=='t'||c=='v'||c=='w'||c=='x'||c=='y'||c=='z');
    }
}

- akumarfun October 13, 2016 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Below is the implementation in C++

#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <locale>

using namespace std;

enum StrType { GOOD, BAD, MIXED };

bool isChar(char c)
{
  if(c >= 'a' && c <= 'z')
    return true;

  return false;
}

bool isVowel(char c)
{
  if(c == 'a' || c == 'e' || c == 'i'
      || c == 'o' || c == 'u')
    return true;
  return false;
}

StrType checkStrType(string str)
{
  int vcnt = 0, vcnt_mixed = 0;
  int ccnt = 0, ccnt_mixed = 0;

  bool mixed = false;

  for_each(str.begin(), str.end(), [](char &x){x = tolower(x);});

  for(int i = 0; i < str.size(); i++){
    if(isChar(str[i])){
      if(isVowel(str[i])){
        vcnt++;
        if(vcnt_mixed > 0)
          vcnt_mixed++;
        ccnt = ccnt_mixed = 0;
      }
      else {
        ccnt++;
        if(ccnt_mixed > 0)
          ccnt_mixed++;
        vcnt = vcnt_mixed = 0;
      }
    }
    else if(str[i] == '?'){
      vcnt_mixed += vcnt + 1;
      ccnt_mixed += ccnt + 1;
      vcnt = ccnt = 0;
    }

    if(vcnt >= 3 || ccnt >= 5)
      return BAD;

    if(vcnt_mixed >= 3 || ccnt_mixed >= 5)
      mixed = true;
  }

  return mixed ? MIXED : GOOD;
}

Here are some test results.

abc : GOOD
abcdefghjkl : BAD
abcd?eg : GOOD
abcd?eij : MIXED
abcd?keij : MIXED
abcd??eij : MIXED
kbd??ej : MIXED
kbd?e? : MIXED
?aa : MIXED
 : GOOD
jk : GOOD

- linuxchain October 13, 2016 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

class test
{

	public static void main(String ar[])
	{
	   String s="dsjg?uoaerfgkahe";
	   String v="aeiou";
	   int vo=0,cons=0,flag1=0,flag2=0;
	   char ch[]=s.toCharArray();
           for(int i=0;i<s.length();i++)
		{
			  if((v.contains(""+ch[i]) || ch[i]=='?')&&i<s.length()-3)
		                {
		                    if((v.contains(""+ch[i+1]) || ch[i+1]=='?') && (v.contains(""+ch[i+2]) || ch[i+2]=='?'))vo=1;
	                            if(ch[i]=='?'|| ch[i+1]=='?'|| ch[i+2]=='?')flag1=1;
		                }
			  if((!v.contains(""+ch[i])||ch[i]=='?')&&i<s.length()-5)
				{
				     if((!v.contains(""+ch[i+1])||ch[i+1]=='?')&&(!v.contains(""+ch[i+2])||ch[i+2]=='?')&&(!v.contains(""+ch[i+3])||ch[i+3]=='?')&&(!v.contains(""+ch[i+4])||ch[i+4]=='?'))
					cons=1;
	                             if(ch[i]=='?'||ch[i+1]=='?'||ch[i+2]=='?'|| ch[i+3]=='?'||ch[i+4]=='?')flag2=2;
				}
	                 
		}

		if(flag1!=0 && flag2!=0)
		     System.out.println("MIXED");
		else if(vo!=0||cons!=0)
		     System.out.println("BAD");
		else
		     System.out.println("GOOD");
         }
}

- Anonymous November 05, 2016 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

class test
{

	public static void main(String ar[])
	{
	   String s="dsjg?uoaerfgkahe";
	   String v="aeiou";
	   int vo=0,cons=0,flag1=0,flag2=0;
	   char ch[]=s.toCharArray();
           for(int i=0;i<s.length();i++)
		{
			  if((v.contains(""+ch[i]) || ch[i]=='?')&&i<s.length()-3)
		                {
		                    if((v.contains(""+ch[i+1]) || ch[i+1]=='?') && (v.contains(""+ch[i+2]) || ch[i+2]=='?'))vo=1;
	                            if(ch[i]=='?'|| ch[i+1]=='?'|| ch[i+2]=='?')flag1=1;
		                }
			  if((!v.contains(""+ch[i])||ch[i]=='?')&&i<s.length()-5)
				{
				     if((!v.contains(""+ch[i+1])||ch[i+1]=='?')&&(!v.contains(""+ch[i+2])||ch[i+2]=='?')&&(!v.contains(""+ch[i+3])||ch[i+3]=='?')&&(!v.contains(""+ch[i+4])||ch[i+4]=='?'))
					cons=1;
	                             if(ch[i]=='?'||ch[i+1]=='?'||ch[i+2]=='?'|| ch[i+3]=='?'||ch[i+4]=='?')flag2=2;
				}
	                 
		}

		if(flag1!=0 && flag2!=0)
		     System.out.println("MIXED");
		else if(vo!=0||cons!=0)
		     System.out.println("BAD");
		else
		     System.out.println("GOOD");
         }
}

- Anonymous November 05, 2016 | 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