Epic Systems Interview Question for Software Engineer / Developers


Country: United States
Interview Type: In-Person




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

bool IsAMatch(string actual, string expected)
{
	char faultyKey = '\0';
	int i = 0, j = 0;
	for(; i < expected.length() && j < actual.length(); ++i)
	{
		if(actual.at(j) != expected.at(i))
		{
			if('\0' != faultyKey)
			{
				if(faultyKey != expected.at(i))
					return false;
			}
			else
			{
				faultyKey = expected.at(i);
			}
		}
		else
		{
			++j;
		}
	}

	return (i == expected.length() - 1 && j == actual.length() - 1)? true : false;
}

- mindless monk November 14, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
2
of 4 votes

Your code is right. It only fails when faulty number is next is at the end.
for example Instead of 18684 u get input as
a. 1868488 - result for this should be true
b. 1868466 - result for this should be false
with your code for both input you will get false. You just have to add extra check so additional code will be:

while(i<expected.length()&& expected.at(i)==faultyKey )
	{
		i++;	
	}

- Tester March 03, 2014 | Flag
Comment hidden because of low score. Click to expand.
2
of 2 votes

shouldn't the i and j equal to the string length, instead of length-1 at last checking?

- sunraincyq March 07, 2014 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

Tester, how can you get 1868488 as the input??? since '8' is the key out of working in this example, which means this string would be regarded as "164" also.

- Anonymous April 30, 2014 | Flag
Comment hidden because of low score. Click to expand.
2
of 2 votes

The code does has problem. But it may not be as the tester said. It's true we can't get the input as 1868488 since the '8' is the not working key, however, we may have the expected as 186848 or 186847. Now when actual input is 164,
for 186848 as expected, the result should be right;
for 186847 as expected, the result should be wrong.
But the mindless's code will regard both as wrong.
And the modification is similar to tester's solution. The code is shown as follows.

public boolean checkValid(String actual, String expected){
		char faultKey = '\0';
		int i = 0, j = 0;
		for(;i<actual.length() && j < expected.length();j++){
			if(actual.charAt(i)!=expected.charAt(j)){
				if(faultKey == '\0'){
					faultKey = expected.charAt(j);
				}else{
					if(faultKey != expected.charAt(i))
							return false;
				}
				i--;
			}
			i++;
		}
		while(j<expected.length() && expected.charAt(j) == faultKey)
			j++;
		return (i==actual.length() && j == expected.length())? true:false;
	}

- kira August 04, 2014 | Flag
Comment hidden because of low score. Click to expand.
2
of 2 votes

I think we need to consider the invalid input like actual = "1246" expected = "12646". We can check this by adding this condition

if(actual.charAt(i) != expected.charAt(j)) {
				if(fault == '\0') 
					fault = expected.charAt(j);
				else {
					if(expected.charAt(j) != fault) return false;
				}
				--i;
			}
			// Extra check added
			else{
				if(fault != '\0' && actual.charAt(i) == fault) return false;
			}
			++i;

- VB November 08, 2014 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

How about
expected = 123488888
enter = 1234
&&
expected = 12344444
enter = 1234
For both cases above, badkey == '\0'

- jiang May 30, 2015 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

#include <stdio.h>
void check(int,int);

int main()

{
	int a,b;
	printf("this program works only for positive integers \n");
	printf("enter expected passwd \n");
	scanf("%d",&a);
	printf("enter input passwd \n");
	scanf("%d",&b);

	check(a,b);
	return 0;
}

void check(int op, int ip)
{
	int flag_digit = 0;
	int k1,k2,k3;
	int faulty_digit;
	
	while(op){

	k1 = op%10;
	k2 = ip%10;
	k3 = 1;
	if(k1==k2){
	
	op = op/10;
	ip = ip/10;
	}

	else{

	if(!flag_digit){
	
	faulty_digit = k1;
	flag_digit++;
	op=op/10;
	k3++;
	}

	if(faulty_digit != k1){
	printf("Incorrect password \n");
	break;
	}

	if(faulty_digit == k1 && (k3 ==1)){
	op = op/10;
	}
	}
	
}

- An Enthusiast November 14, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

I guess it wont work if
faulty key is 4.
expected password :- 145645
input password :- 1565

- mayank November 15, 2013 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

@Mayank:

You are wrong. This program works fine for the input which you gave.

- CodeNinja March 07, 2014 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

Here is a working code in C++. I have basically used hashing to keep a count of each digit that occurs in both the passwords. If I find that more then two digits vary in their hashed values then it is a wrong password. If no such condition occurs (i.e. only one digit difference is there) then I further go on to check the correct ordering of the digits within the number. Each time I come across the digit whose hashed value differed I simply skip it. If there is a mismatch and it is not that particular digit then it is a wrong password.

#include <cstdio>
#include <iostream>
#include <math.h>

using namespace std;

int main()
{
    long long int temp2, flag=0, temp, num1, num2, arr1[10], arr2[10], i, dig;
    cin>>num1;
    cin>>num2;
    for (i=0; i<10; i++)
    {
        arr1[i]=arr2[i]=0;
    }
    temp=num1;
    while (temp!=0)
    {
        arr1[temp%10]++;
        temp/=10;
    }
    temp=num2;
    while (temp!=0)
    {
        arr2[temp%10]++;
        temp/=10;
    }
    for (i=1; i<10; i++)
    {
        if ((arr1[i]!=arr2[i]) && flag==1)
        {
            cout<<"Wrong password"<<endl;
            exit(0);
        }
        else if((arr1[i]!=arr2[i]) && flag==0)
        {
            dig=i;
            flag=1;
        }
    }
    temp=num1;
    temp2=num2;
    flag=0;
    while (temp2!=0)
    {
        if (((temp2%10)!=(temp%10)) && (temp2%10!=dig))
        {
            cout<<"Wrong Password"<<endl;
            flag=1;
            break;
        }
        if (((temp2%10)!=(temp%10)) && (temp2%10==dig))
        {
            temp2/=10;
        }
        else
        {
            temp/=10;
            temp2/=10;
        }
    }
    if (flag==0)
    {
        cout<<"Right password"<<endl;
    }
    return 0;
}

- Meraj Ahmed November 15, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 2 vote

static boolean isValidPassword(String act, String exp) {
		if (act.length() == 0 && exp.length() == 0) {
			return true;
		}
		if (act.length() == 0)
			return false;
		char notWorkingPad = '0';
		int j=0;
		for (int i = 0; i < exp.length(); i++) {
				if (exp.charAt(i) != act.charAt(j)) {
					if (notWorkingPad == '0') {
						notWorkingPad = exp.charAt(i);
						
					} else {
						if (notWorkingPad != exp.charAt(i)) {
							return false;
						}
					}
				}
				else{j++;}
		}
		return true;

}

- Bunnyyoung717 November 16, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

Same issue with your code. if the wrong number is at the end of the actual string, then your code is wrong. You can just add a checker before your checking.
public class keypad
{
static boolean isValidPassword(String act, String exp)
{
if (act.length() == 0 && exp.length() == 0)
{
return true;
}
if (act.length() == 0)
return false;

char notWorkingPad = '0';
int j = 0;
for (int i = 0; i < exp.length(); i++)
{
if (j >= act.length())
{
if (notWorkingPad != exp.charAt(i))
{
return false;
}
}

if (exp.charAt(i) != act.charAt(j))
{
// get the not working pad
if (notWorkingPad == '0')
{
notWorkingPad = exp.charAt(i);

}
else
{
if (notWorkingPad != exp.charAt(i))
{
return false;
}
}
}
else
{
j++;
}
}
return true;
}

public static void main(String[] args)
{
System.out.println(isValidPassword("164", "164"));
System.out.println(isValidPassword("164", "1868888847665"));
}
}

- yuchaozh1991 October 15, 2014 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

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

int valid(char *pass, char *str, int lengthpass, int lengthstr, int value) {
	int i = 0;
	int j = 0;

	for(i =0 ; i < lengthpass ;) {
		if(pass[i] != str[j]) {
			if(pass[i]-'0' == value) {
				i++;
			}
			else {
				return 0;
			} 
		}
		else {
			i++;
			j++;
		}
	}
	return 1;
}
	
int main() {

	char *str = "1565";
	char *password = "145645";
	if(valid(password, str, strlen(password), strlen(str), 4)) {
		printf("valid\n");
	}
	else
		printf("invalid\n");
		
	return 0;
}

- abhi November 17, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

This code works fine! (I think)

string expected, ent;

bool pwdMatch(int i, int j, char &miss){
    if(i==expected.size() && j==ent.size()) return true;
    if(i==expected.size() && j<ent.size()) return false;
    if(i<expected.size() && j==ent.size()){
        if(miss=='x') miss=expected[i];
        else if(expected[i]!=miss){ return false;}
        return pwdMatch(i+1,j,miss);
    }
    if(expected[i]==ent[j]) return pwdMatch(i+1,j+1,miss);
    if(expected[i] != ent[j] && miss=='x'){

        miss=expected[i];
        return pwdMatch(i+1,j,miss);
    }
    if(expected[i] != ent[j] && expected[i]==miss){
        return pwdMatch(i+1,j,miss);
    }
    if(expected[i] != ent[j] && expected[i]!=miss){
        return false;
    }
}

int main(){
    cin>>expected>>ent;
    char miss='x';
    if(pwdMatch(0,0,miss)) cout<<"correct match\n";
    else cout<<"invalid password\n";
}

- Ayush November 18, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

public static void Main(string[] args)
{
vald("164","881684","8");
}

public static void vald(string ent,string exp,string f)
{
string ente= exp.Replace(f,"");
Console.Write(ente);
if(ente.Equals(ent))
Console.Write("match");
else
Console.Write("not match match");

Console.Read();
}

- Arun November 22, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

public boolean isMatch(String input, String expected) {
		if(input==""&&expected=="")
			return true;
		if(input.length()>expected.length())
			return false;
		char missed = 0;
		int i = 0;
		int j = 0;
		while(i<input.length()) {
			if(input.charAt(i)==expected.charAt(j)) {
				i++;
				j++;
			}else {
				if(missed!=0&&expected.charAt(j)!=missed)
					return false;
				else {
					missed = expected.charAt(j);
					for(int k=0; k<=i; k++) {
						if(input.charAt(k)==missed)
							return false;
					}
				}
				j++;
			}
		}
		if(j==expected.length())
			return true;
		else {
			for(int k=j; k<expected.length(); k++) {
				if(expected.charAt(k)!=missed)
					return false;
			}
			return true;
		}
	}

- sz2376@columbia.edu December 01, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Python code.

def main():
    expected_password=raw_input("Enter the expected password:")
    actual_password=raw_input("Enter the actual Password:")
    faulty_digit=[]
    missmatch=[]
    l=len(expected_password)
    k=len(actual_password)
    j,i=0,0
    if k<=l:
        while i<k and j<l:
            if actual_password[i]==expected_password[j]:
                j=j+1
                i=i+1
            else:
                missmatch.append(j)
                j=j+1
        for i in missmatch:
            faulty_digit+=expected_password[i]
        z=len(set(faulty_digit))
        if z!=1 and z>0:
            print "Wrong Password"
        else:
            print "Password accepted"        
    else:
        print "Wrong Password"
                
if __name__ == "__main__":
    main()

- sidharth December 11, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Wouldn't it be sufficient if we just check the length's of the expected and actual strings?

- Anonymous December 11, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

#include<iostream>

using namespace std;

int main()
{
	int arr[10],ent,exp,temp=0;
	cin>>exp;
	for(int i=0;i<10;i++)
		arr[i]=0;
	
	temp=exp;
	while(temp)
	{
		arr[temp%10]++;
		temp=temp/10;
	}
	cin>>ent;
	temp=ent;
	while(temp)
	{
		arr[temp%10]--;
		temp=temp/10;
	}
	int count=0;
	for(int i=0;i<10;i++)
	{
		if(arr[i]!=0)
		count++;
	}
	if(count>1)
		cout<<"Invalid";
	else
		cout<<"Valid";
	
	
	return 0;
}

- crusader December 23, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

we need to know either which key is faulty, or no. of keys entered by the user
if we know the faulty key, we can simply check
Let faulty key be m
sum (i..n) of entered pwd + (len(actual_pwd)-len(entered_pwd)) * m = sum (i..k) of actual pwd

- gj December 25, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

int enteredPwd = 164;
		int expectedPassword = 18684;
		
		int faultKey = 9;
		
		int enteredNo = enteredPwd;
		int expectedNo = expectedPassword;
		
		
		if (enteredNo == expectedNo) {
			System.out.println("Password Correct");
		} else {
			while (enteredNo > 0 && expectedNo > 0) {
				
				int enteredRem = enteredNo % 10;
				int enteredQuo = enteredNo / 10;
				int expectedRem = expectedNo % 10;
				int expectedQuo = expectedNo / 10;
				if (enteredRem == expectedRem) {
					enteredNo = enteredQuo;
					expectedNo = expectedQuo;
				} else {
					
					if (expectedRem == faultKey) {
						expectedNo = expectedQuo;
					} else {
						System.out.println("Password Wrong");
						System.exit(0);
					}
					
				}
				
			}
			
			
			System.out.println("Password Correct");
			
		}

- Senthil Nathan Chockalingam February 13, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

this should be the right one :
check it out

public static void epic(int[][] m) {
        if(m.length==0 || m[0].length==0)
            return;
        int[][] dp = new int[m.length][m[0].length];
        int max= 0;
        for(int i=1;i<m.length;i++){
            for(int j=1;j<m[0].length;j++){
                if(Math.abs(m[i-1][j]-m[i][j])==1){
                    dp[i][j] = Math.max(dp[i][j],dp[i-1][j]+1);
                    max = Math.max(max,dp[i][j]);
                }
                if(Math.abs(m[i][j-1]-m[i][j])==1){
                    dp[i][j] = Math.max(dp[i][j],dp[i][j-1]+1);
                    max = Math.max(max,dp[i][j]);
                }
            }
        }

        for(int i=0;i<m.length;i++){
            for(int j=0;j<m[0].length;j++){
                if(dp[i][j]==max){
                    printsnake(m,dp,i,j,new Stack<Integer>());
                }
            }
        }
    }

    public static void printsnake(int[][] m,int[][] dp,int row,int col,Stack<Integer> stack){
        if(dp[row][col] == 0){
            System.out.print(" snake: "+m[row][col]+" ");
            Stack<Integer> s = (Stack<Integer>)stack.clone();
            while(!s.isEmpty()){
                System.out.print(s.pop()+" ");
            }
            System.out.println();
        }
        stack.add(m[row][col]);
        if(row>0 && dp[row-1][col]+1==dp[row][col]){
            printsnake(m,dp,row-1,col,stack);
        }
        if(col>0 && dp[row][col-1] +1==dp[row][col])
            printsnake(m,dp,row,col-1,stack);
        stack.pop();
    }

- chenyang.feng.cn April 06, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

int a[][] = {{1,2,3,2,5},{1,3,4,3,2},{1,2,1,2,1} };

out put :
snake: 2 3 4 3 2 1
snake: 1 3 4 3 2 1
snake: 2 3 4 3 2 1
snake: 1 3 4 3 2 1
snake: 2 3 4 1 2 1
snake: 1 3 4 1 2 1
snake: 2 3 2 1 2 1
snake: 1 3 2 1 2 1

- chenyang.feng.cn April 06, 2014 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

public class PasswordChecker
{
	public static boolean isValidPassword(String input, String expected)
	{
		String temp = "";
		// remove all possible characters once at a time
		for (int i = (int) '1'; i <= (int) '9'; i++)
		{
			// Check if current character exists in expected pw and
			// doesn’t exist in input
			if (!input.contains(((char) i)+"") && expected.contains(((char) i)+""))
			{
				// remove all occurrences of character in expected
				temp = expected.replaceAll(((char) i)+"", "");
				// return true if it is the same as input
				if (input.equals(temp))
					return true;
			}
		}
		return false;
	}

	public static void main(String[] args)
	{
		System.out.println(isValidPassword("1698324786", "15698532547856")); // true
		System.out.println(isValidPassword("16983286", "15698532547856")); // false
	}
}

- Mahmoud El-Maghraby June 29, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

int is_legal(char *ex,char *rec)
	{
	int j=0,i;
	char mis;
	while(ex[j]==rec[j])j++;
	mis=ex[j];
	i=j;
	while(ex[j])
		{
		if(ex[j]==mis)j++;
		else if(ex[j]==rec[i]){j++;i++;}
		else return 0;
		}
	return 1;
	}

- sanjiv kumar July 27, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

I didn't see all the codes posted but went through for some of them. My idea is simple. Just store 1st non-matching character/number in both provided numbers. This number will be our fault number which can not be pressed. If we find any other non-matching number and that number is also not matching to previous fault number, then it means there are more than two fault numbers which can not be true. So return.

private static boolean isFaultyPasscode(char[] entered, char[] actual) {
        if (actual == null || entered == null)
            return true;
        
        if (actual.length < entered.length)
            return true;
        
        char faultChar = '\0';
        int i,j;
        i=j=0;
        
        while (i<actual.length && j<entered.length) {
            if (entered[j] != actual[i]) {
                if (faultChar == '\0')
                    faultChar = actual[i++];
                else {
                    if (actual[i++] == faultChar)
                        continue;
                    else
                        return true;
                }
            }
            else {
                i++;
                j++;
            }
        }
        
        if (j != entered.length)
            return true;
            
        while (i<actual.length) {
            if (actual[i++] != faultChar)
                return true;
        }
        
        return false;
    }
    
    public static void main(String args[])
    {
        String entered = "1565";
        String actual = "145645";
        System.out.println("Is a faulty code entered?: "+isFaultyPasscode(entered.toCharArray(), actual.toCharArray()));
    }

- left4dead October 05, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

def check(e,a):
	flag=""
	for i in range(len(e)):
		if e[i]!=a[i]:
			flag=e[i]
			break
	newe=""
	for i in range(len(e)):
		if e[i]!=flag:
			newe+=e[i]
			print newe
	return newe==a

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

working

#include <string>
#include <iostream>

using namespace std;

bool validPwd(string entered, string expected) {
	if (entered == expected) return true;
	char faultKy = 'm';
	int i = 0; 
	for(int j = 0; j < expected.length(); ++j) {
		if(i < entered.length()){
			if (expected[j] != entered[i]) {
				if(faultKy != 'm' && faultKy != expected[j]) {
					return false;
				} else if(faultKy == 'm') {
					faultKy = expected[j];
				}
			} else { 
				if(i == entered.length() - 1 && j == expected.length() - 1) {
					return true;
				} else {
					++i;
				}
			}
		} else {
			if (faultKy != expected[j]) return false;
		}
	}
	return true;
}

void main() {
	bool tmp = validPwd("164","1868466");
	cout << tmp <<endl;
	cin.get();
}

- 9610 October 19, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

import java.util.*;
public class validPassword{
	
	public static void main(String args[]){
		String actualPassword = "18864";
		String enteredPassword ="164";
		ArrayList<Integer> actualPasswordDigits = new ArrayList<Integer>();
		ArrayList<Integer> enteredPasswordDigits = new ArrayList<Integer>();

		int iActualPassword = Integer.parseInt(actualPassword);
		int iEnteredPassword = Integer.parseInt(enteredPassword);

		while(iActualPassword !=0){	
			int temp = iActualPassword%10;
			if(!actualPasswordDigits.contains(temp)){
				actualPasswordDigits.add(temp);
			}
			iActualPassword = iActualPassword/10;
		}

		while(iEnteredPassword !=0){
			int temp = iEnteredPassword%10;
			if(!enteredPasswordDigits.contains(temp)){
				enteredPasswordDigits.add(temp);
			}
			iEnteredPassword = iEnteredPassword/10;
		}

		if(Math.abs(actualPasswordDigits.size() - enteredPasswordDigits.size()) > 1 ){
			System.out.println("Invalid Password");
			System.exit(0);
		}
		
		Collections.reverse(enteredPasswordDigits);
		Collections.reverse(actualPasswordDigits);
		
		for(int i = 0; i<actualPasswordDigits.size();i++){
			if(enteredPasswordDigits.indexOf(actualPasswordDigits.get(i)) > i){
				System.out.println("Invalid Password due to sequence");
				System.exit(0);
			}
		}

		System.out.println("Valid password");
	}

}

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

What's the meaning of this question? If user enters 818684, while you expect 18684, should we still return true since the computer only sees 164? Anyway, if that's what EPIC wants, we can come up with the following two ideas.
* We can either eliminate all faulty chars in expected string and do string compare,
* or compare two strings char by char. If faulty chars are found in expected string, skip.
Playable code at:

ideone.com/DtlAK2

bool checker(string actual, string expected, char fault) {
	if (actual.size() > expected.size()) return false;
	int actPt(0), expPt(0);
	while (actPt != actual.size() && expPt != expected.size()) {
		if (expected[expPt] == fault) {
			++expPt;
			continue;
		}
		if (actual[actPt] != expected[expPt]) return false;
		++actPt, ++expPt;
	}
	while (expPt != expected.size() && expected[expPt] == fault) ++expPt;
	return actPt == actual.size() && expPt == expected.size();
}

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

public class ValidPassword {

public static boolean isValidPwd(String input, String expected){
if(input.equals(expected)) return true;
if(input.length()>expected.length()) return false;
char diff=expected.charAt(expected.length()-1);
for(int i=0;i<input.length();i++){
if(input.charAt(i)!=expected.charAt(i)){
diff=expected.charAt(i);
break;
}
}
String compare=expected.replace(String.valueOf(diff),"");
if(input.equals(compare)) return true;
else return false;
}

public static void main(String[] args){
System.out.println(isValidPwd("164","16477"));
}

}

- Juliet March 05, 2015 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

public class ValidPassword {
  
  public static boolean isValidPwd(String input, String expected){
    if(input.equals(expected)) return true;
    if(input.length()>expected.length()) return false;
    char diff=expected.charAt(expected.length()-1);
    for(int i=0;i<input.length();i++){
      if(input.charAt(i)!=expected.charAt(i)){
        diff=expected.charAt(i);
        break;
      }
    }
    String compare=expected.replace(String.valueOf(diff),"");
    if(input.equals(compare)) return true;
    else return false;
  }
  
  public static void main(String[] args){
    System.out.println(isValidPwd("164","16477"));
  }

}

- Juliet March 05, 2015 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

public class Password_match 
{
private static boolean isFaultyPasscode(int given, int pass) 
{    char [] entered =(""+given).toCharArray();
     char[] expected =(""+pass).toCharArray();
	if (expected == null || entered == null)
		return true;

	if (entered.length == 0 || entered.length>expected.length)
		return false;

	char key_faulty = '\0';
	int i,j;
	j=0;
	

	for(i=0; i<expected.length; i++) 
	{
		
		if(i>j)
		{
			if(expected[i] == key_faulty)
			{
				return true;
			}
			
		}
		else if (entered[j] != expected[i]) 
		{
			if (key_faulty == '\0')
			{
				key_faulty = expected[i];
			}
			else {
				if (expected[i] == key_faulty)
				{
					i++;
					continue;
				}
				else
					return false;
			}
		}
		else
		{
			
			
		j++;
		
			
	}
	}
	return true;

	
}

public static void main(String args[])

{
	int entered = 151;
	int expected = 14514;
	System.out.println("Entered password is valid ? "+isFaultyPasscode(entered, expected));
}
}

- Khushboo July 29, 2015 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

public class Password_match 
{
private static boolean isFaultyPasscode(int given, int pass) 
{    char [] entered =(""+given).toCharArray();
     char[] expected =(""+pass).toCharArray();
	if (expected == null || entered == null)
		return true;

	if (entered.length == 0 || entered.length>expected.length)
		return false;

	char key_faulty = '\0';
	int i,j;
	j=0;
	

	for(i=0; i<expected.length; i++) 
	{
		
		if(i>j)
		{
			if(expected[i] == key_faulty)
			{
				return true;
			}
			
		}
		else if (entered[j] != expected[i]) 
		{
			if (key_faulty == '\0')
			{
				key_faulty = expected[i];
			}
			else {
				if (expected[i] == key_faulty)
				{
					i++;
					continue;
				}
				else
					return false;
			}
		}
		else
		{
			
			
		j++;
		
			
	}
	}
	return true;

	
}

public static void main(String args[])

{
	int entered = 151;
	int expected = 14514;
	System.out.println("Entered password is valid ? "+isFaultyPasscode(entered, expected));
}
}

- Anonymous July 29, 2015 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

package EPi;

public class Password_match 
{
private static boolean isFaultyPasscode(int given, int pass) 
{    char [] entered =(""+given).toCharArray();
     char[] expected =(""+pass).toCharArray();
	if (expected == null || entered == null)
		return true;

	if (entered.length == 0 || entered.length>expected.length)
		return false;

	char key_faulty = '\0';
	int i,j;
	j=0;
	

	for(i=0; i<expected.length; i++) 
	{
		
		if(i>j)
		{
			if(expected[i] == key_faulty)
			{
				return true;
			}
			
		}
		else if (entered[j] != expected[i]) 
		{
			if (key_faulty == '\0')
			{
				key_faulty = expected[i];
			}
			else {
				if (expected[i] == key_faulty)
				{
					i++;
					continue;
				}
				else
					return false;
			}
		}
		else
		{
			
			
		j++;
		
			
	}
	}
	return true;

	
}

public static void main(String args[])

{
	int entered = 151;
	int expected = 14514;
	System.out.println("Entered password is valid ? "+isFaultyPasscode(entered, expected));
}
}

- anonymous July 29, 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