A9 Interview Question for Applications Developers


Country: India
Interview Type: Phone Interview




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

import java.io.*;
import java.util.*;
class Abc
{
public static void main(String args[])throws IOException
{
int a,b;
String s,s1,s2,s3,s4;
BufferedReader input = new BufferedReader(new InputStreamReader(System.in));
//InputStreamReader isr = new InputStreamReader(input);
System.out.println("Enter the 1st string with * in the string at any position");
s=input.readLine();
System.out.println("Enter the 2st string with * in the string at any position");
s1=input.readLine();
a=s.indexOf('*');
b=s1.indexOf('*');
System.out.println("index of string 1 is at "+a);
System.out.println("index of string 2 is at:"+b);

if(a!=b)
System.out.println("not possible");
else{

s2=s.substring(0, +a);
s3=s1.substring(0, +b);
System.out.println(s2 );
System.out.println(s3 );

s4=s2.concat(s3);

System.out.println(s4);


}


}
}


//try it...seems legit to me

- sandy August 02, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

shit...sorry...i chdk the position of * instead of lenth of string......just add the command length() for checking the length of both the strings and if it is equal then add :)
I checkd with the strings of same length hence i got the ans....and pls correct if it is wrong :)

- sandy August 02, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

public class FindAstrix {
    public static void main(String[] args) {
        String A = "ABC*EFG", B = "ABCDE*G";
        int indexOfA = A.indexOf('*'), indexOfB = B.indexOf('*');
        if (A.length() != B.length() || indexOfA == -1 || indexOfB == -1 || indexOfA == indexOfB) {
            System.out.println("NOT-POSSIBLE");
        } else if (indexOfA > indexOfB) {
            System.out.println(_findMissingChar(A, B));
        } else if (indexOfA < indexOfB) {
            System.out.println(_findMissingChar(B, A));
        }
    }

    private static String _findMissingChar(String str1, String str2) {
        String[] parts = str1.split("\\*");
        int index = str2.indexOf(parts[0]);
        if (index >= 0) {
            return parts[0] + str2.charAt(index + 1) + parts[1];
        } else {
            index = str2.indexOf(parts[1]);
            return parts[0] + str2.charAt(index - 1) + parts[1];
        }
    }
}

- sam.gvp August 03, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

import java.io.*;
class MyTest {
	public static void main(String[] args)throws IOException {
		String s1,s2;
		BufferedReader reader=new BufferedReader(new InputStreamReader(System.in));
		System.out.println("enter two Strings");
		s1=reader.readLine();
		s2=reader.readLine();
		if (!(check(s1) && check(s2)))
			System.out.println("not possible");
		else
			System.out.println(match(s1,s2));
	}
	public static String match(String s1,String s2){
		String s3,s4;
		String[] str1=s1.split("\\*");
		String[] str2=s2.split("\\*");
		int l1=str1.length;
		int l2=str2.length;
		int l3=l1>=l2?l1:l2;
		if (l3==1){
			if (str1[0].contains(str2[0])||str2[0].contains(str1[0]))
				s3=str1[0].length()>str2[0].length()?str1[0]:str2[0];
			else
				s3="not possible";
		}
		else{
			if ((str1[0].contains(str2[0])||str2[0].contains(str1[0]))&&(str1[1].contains(str2[1])||str2[1].contains(str1[1]))){
				s3=str1[0].length()>str2[0].length()?str1[0]:str2[0];
				int l=s3.length();
				if (s1.contains(s3))
					s4=s2.substring(l,s2.length());
				else
					s4=s1.substring(l,s1.length());
				s3=s3+s4;
			}
			else
				s3="not possible";
		}
		return s3;
	}
	public static boolean check(String str){
		int count=0;
		char c[]=str.toCharArray();
		for (int i=0;i<str.length() ;i++ ){
			if (c[i]=='*')
			count++;
		}
		if (count>1)
			return false;
		else return true;
	}
}

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

public static String rearrangeWord(String a,String b)
	{
		if(a.length() == b.length())
		{
			char [] strA = a.toCharArray();
			char [] strB = b.toCharArray();

			for(int x = 0 ; x < a.length() ; x++)
			{
				if(strA [x] == '*')
				{
					strA[x] = strB[x];
				}
				else if(strB[x] == '*')
				{
					strB[x] = strA[x];
				}
			}
			return String.valueOf(strA);
		}

		return "Not possible";

}

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

public static String rearrangeWord(String a,String b)
	{
		if(a.length() == b.length())
		{
			char [] strA = a.toCharArray();
			char [] strB = b.toCharArray();

			for(int x = 0 ; x < a.length() ; x++)
			{
				if(strA [x] == '*')
				{
					strA[x] = strB[x];
				}
				else if(strB[x] == '*')
				{
					strB[x] = strA[x];
				}
			}
			return String.valueOf(strA);
		}

		return "Not possible";
	}

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

public static String rearrangeWord(String a,String b)
	{
		if(a.length() == b.length())
		{
			char [] strA = a.toCharArray();
			char [] strB = b.toCharArray();

			for(int x = 0 ; x < a.length() ; x++)
			{
				if(strA [x] == '*')
				{
					strA[x] = strB[x];
				}
				else if(strB[x] == '*')
				{
					strB[x] = strA[x];
				}
			}
			return String.valueOf(strA);
		}

		return "Not possible";
	}

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

#include <iostream>

using namespace std;

string findCommon(string a, string b)
{
    int i=0, j=0, m=a.size(), n=b.size();

    string ans;

    while(i<m and j<n)
    {
        cout << a[i] << " " << b[j] << endl;
        if(a[i]==b[j] and a[i]=='*')
        {
            i++;
            j++;
            continue;
        }

        if(a[i]!=b[j] and a[i]!='*' and b[j]!='*')
            return "not-possible";

        if(a[i]==b[j] and a[i]!='*')
        {
            ans+=a[i];
            i++;
            j++;
            continue;
        }

        if(a[i]=='*')
        {
            if(i==m-1)
            {
                int temp=b.find('*');
                if(temp<j)
                    ans+=b.substr(j);
                else
                    ans+=b.substr(j, temp-j)+b.substr(temp+1, n-temp-1);
                break;
            }
            while(j<n and a[i+1]!=b[j] and b[j]!='*')
            {
                ans+=b[j];
                j++;
            }
            if(j==n)
                return "not-possible";
            else
                i++;
            continue;
        }

        if(b[j]=='*')
        {
            if(j==n-1)
            {
                int temp=a.find('*');
                if(temp<i)
                    ans+=a.substr(i);
                else
                    ans+=a.substr(i, temp-i)+a.substr(temp+1, m-temp-1);
                break;
            }
            while(i<m and b[j+1]!=a[i] and a[i]!='*')
            {
                cout << "adding " << a[i] << endl;
                ans+=a[i];
                i++;
            }
            if(i==m)
                return "not-possible";
            else
                j++;
            continue;
        }
    }
    return ans;
}
int main()
{
    cout << findCommon("*c", "d*");
    return 0;
}

- ibimd October 07, 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