Flipkart Interview Question for SDE-2s


Country: United States




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

import java.util.Scanner;
import java.util.regex.Pattern;

public class Solution {

	public static void main(String[] args) {
		
		Scanner sc = new Scanner(System.in);
		
		System.out.println("Enter pattern: "); 
		String pattern = sc.next();
		
		System.out.println("Enter string: ");
		String input = sc.next();
		
		if(Pattern.matches(pattern, input)){
			System.out.println("There is a match");
		} else {
			System.out.println("There isn't a match");
		}
	}

}

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

import java.util.Scanner;
import java.util.regex.Pattern;

public class Solution {

	public static void main(String[] args) {
		
		Scanner sc = new Scanner(System.in);
		
		System.out.println("Enter pattern: "); 
		String pattern = sc.next();
		
		System.out.println("Enter string: ");
		String input = sc.next();
		
		if(Pattern.matches(pattern, input)){
			System.out.println("There is a match");
		} else {
			System.out.println("There isn't a match");
		}
	}

}

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

^[a-zA-Z]*$

- Satyabrat January 22, 2016 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

/* Adopted from Rob Pike's implementation  */
#include <iostream>
#include <stdio.h>

using namespace std;

bool RegExMatchHelper(char* regex, char* text);

bool RegExMatchKleeneStar (char c, char* regex, char* text){
    do {
        if(RegExMatchHelper(regex, text)) return true;
    } while (*text != '\0' && (*text++ == c || c == '.'));
    
    return false;
}

bool RegExMatchHelper(char* regex, char* text){
    if(regex[0] == '\0') return true;
    if(regex[0] == '$' && regex[1] == '\0') return *text == '\0';
    if(regex[1] == '*') {
        return RegExMatchKleeneStar(regex[0], regex+2, text);
    } 
    if(*text != '\0' && (*text++ == regex[0] || regex[0] == '.')) {
            return RegExMatchHelper(regex+1, text);
    }
    
    return false;
}

bool RegExMatcher (char* regex, char* text){
    if(regex[0] == '\0') return true;
    
    if(regex[0] == '^') {
        return RegExMatchHelper(regex+1, text);
    } else {
        do {
            if(RegExMatchHelper(regex, text)) return true;
        } while (*text++ != '\0');
    }
    
    return false;
}

int main(int argc, char** argv) {
    if(argc != 3) cout << "Wrong format\n";
    if(RegExMatcher(argv[1],argv[2])) cout << "Match\n";
    else cout << "Doesn't match\n";
    return 0;
}

- diba.bec February 29, 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