GrubHub Interview Question for Software Engineer / Developers


Team: Products
Country: United States
Interview Type: Written Test




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

#include <stdio.h>
#include<ctpye.h>
#include <conio.h>
#include <string.h>


int main()
{
	int i,l1=0,l2=0;
	char str1[30],str2[30];
	printf("\nEnter the string1, string 2:\n");
	scanf("%s%s",str1,str2);
	
	for(i=0;i<strlen(str1);i++)
	{
		if(isdigit(str1[i]))
			l1++;
	}
	for(i=0;i<(strlen(str2));i++)
	{
		if(isdigit(str2[i]))
			l2++;
	}
	if(l1>l2)
		printf("\n%s has more numbers",str1);
	else if(l2>l1) 
		printf("\n%s has more numbers",str2);
	if(l1==l2)
	{
		if(strlen(str1)>=strlen(str2))
			printf("\n%s has more numbers",str1);
		else
			printf("\n%s has more numbers",str2);
	}
	printf("\npress any key to continue");
	getch();
}

- Sunil B N September 02, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

public static String leastNum(String[] myS) {
		
		String[] myHash = new String[10]; //this assumes max 10 numeric characters per string
		int count = 0;
		
		for (String s: myS) {
			for (char c: s.toCharArray()) {
				if (c >= 48 && c <= 57) {
					count++;
				}
			}
			if (myHash[count] != null && s.length() > myHash[count].length()) {
				myHash[count] = s;
			}
			else if (myHash[count] == null){
				myHash[count] = s;
			}
			count = 0;
		}
		
		String solution = null;
		
		for (int i=9; i>=0; i--) {
			if (myHash[i] != null) {
				System.out.println(myHash[i]);
				solution = myHash[i];
				break;
			}
		}
		
		return solution;

}

- Yo Dawg November 10, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

public class FastFindString {

    public String fastFind(String[] array)
    {
        if (array.length == 1)
        {
            return array[0];
        }
        if (array.length == 2)
        {
            if (array[0].equalsIgnoreCase(array[1]))
            {
                return array[0];
            }
        }

        String leastNumString = null;
        int leastCount = -1;

        for (int i=0; i<array.length; i++)
        {
            String str = array[i];
            String num_str = str.replaceAll("[^-?0-9]+", " ");

            if (null != num_str)
            {
                List<String> numList = Arrays.asList(num_str.trim().split(" "));
                int count = numList.size();
                if (i==0)
                {
                    leastCount = count;
                }
                if (count < leastCount)
                {
                    leastCount = count;
                    leastNumString = str;
                }
            }


        }
        return leastNumString;
    }


    public static void main(String[] args)
    {
        FastFindString fastFind = new FastFindString();
        String[] input = {"ABCDEF", "ABCDEF"};
        System.out.println(fastFind.fastFind(input));
    }

}

- rudraksh February 05, 2017 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

public class FastFindString {

    public String fastFind(String[] array)
    {
        if (array.length == 1)
        {
            return array[0];
        }
        if (array.length == 2)
        {
            if (array[0].equalsIgnoreCase(array[1]))
            {
                return array[0];
            }
        }

        String leastNumString = null;
        int leastCount = -1;

        for (int i=0; i<array.length; i++)
        {
            String str = array[i];
            String num_str = str.replaceAll("[^-?0-9]+", " ");

            if (null != num_str)
            {
                List<String> numList = Arrays.asList(num_str.trim().split(" "));
                int count = numList.size();
                if (i==0)
                {
                    leastCount = count;
                }
                if (count < leastCount)
                {
                    leastCount = count;
                    leastNumString = str;
                }
            }


        }
        return leastNumString;
    }


    public static void main(String[] args)
    {
        FastFindString fastFind = new FastFindString();
        String[] input = {"ABCDEF", "ABCDEF"};
        System.out.println(fastFind.fastFind(input));
    }
}

- rudraksh February 05, 2017 | Flag Reply
Comment hidden because of low score. Click to expand.
-1
of 1 vote

xs

- Anonymous September 02, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
-1
of 1 vote

Use treemap with key as number of digits and value as string and it's length(inner class and list of values)

- Anonymous September 12, 2012 | 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