Google Interview Question for Software Engineers


Country: United States




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

void printCombinations(StringBuilder s,int i){
        if(i==s.length()){
            System.out.println(s);
            return;
        }

        if(s.charAt(i)=='?'){
            s.replace(i,i+1,"0");
            printCombinations(s,i+1);
            s.replace(i,i+1,"1");
            printCombinations(s,i+1);
            s.replace(i,i+1,"?");
        }else{
            printCombinations(s,i+1);
        }
    }

- rahulroshan96 May 13, 2019 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Possible combinations with be nCr = n! / r! * (n - r)!
and r should be 2 here as we have only 0 or 1

- Anonymous May 14, 2019 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

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

void print_possible_combination(string input, int pos){
    if(pos >= input.size() || input.find('?', pos) == string::npos){
        cout << input << endl;
        return;
    }
    else{
        pos = input.find('?', pos);
        
        input.replace(pos, 1, "0");
        print_possible_combination(input, pos+1);
        
        input.replace(pos, 1, "1");
        print_possible_combination(input, pos+1);
    }
}

int main(){
    string input; cin >> input;
    print_possible_combination(input, 0);
}

- Mub May 20, 2019 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

////Sample Call

Combination("01?01", 0, "");

public static void Combination(string mainSTring, int counter, string combination_string)
        {
            if (mainSTring.Length == combination_string.Length)
            {
                System.Console.WriteLine(combination_string);
                return;
            }

            if (mainSTring[counter] == '?')
            {
                Combination(mainSTring, counter + 1, combination_string + "0");
                Combination(mainSTring, counter + 1, combination_string + "1");
                return;
            }

            Combination(mainSTring, counter + 1, combination_string + mainSTring[counter]);
        }

- Manoj May 26, 2019 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

def allstr(str1, index, length):
    if index == length:
        print(str1)
        return
    if str1[index] == '?':
        str1[index] = 'T'
        allstr(str1, index + 1, length)
        str1[index] = 'X'
        allstr(str1, index + 1, length)
        str1[index] = '?'
    else:
        allstr(str1, index + 1, length)


t = list('he?l?o?')
allstr(t, 0, t.__len__())

- Praveen Pandit May 30, 2019 | 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