Kony India Private Limited Interview Question for Software Engineer / Developers


Country: India
Interview Type: In-Person




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

boolean isValidIPv4Address(String input){

if(input!=null && !input.equals("")){

Pattern pattern;
Matcher matcher;

final String IPADDRESS_PATTERN =
"^([01]?\\d\\d?|2[0-4]\\d|25[0-5])\\." +
"([01]?\\d\\d?|2[0-4]\\d|25[0-5])\\." +
"([01]?\\d\\d?|2[0-4]\\d|25[0-5])\\." +
"([01]?\\d\\d?|2[0-4]\\d|25[0-5])$";


pattern = Pattern.compile(IPADDRESS_PATTERN);

matcher = pattern.matcher(input);
return matcher.matches();

}
return false;
}

- vijay.lokhande.in September 20, 2017 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

vijay.lokhande.in please read the question properly.
You CANNOT use Pattern class.
ONLY String/StringBuffer/StringBuilder classes allowed

- Interviewer September 20, 2017 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

@intervieweer: java.util.regex.Pattern is not in java.net
probably worth restating the question to "only using StringBuffer String"

what's a valid IP v4 address anyway, is " 1. 9. 2. 0 " valid ? how about "00000.0.0.0" ?

vija.lohande.in specified it in a formal way... and actually quite sophisticated, if you read the regular expression...

- Chris September 20, 2017 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

class ValidIPv4Address {

	public static void main(String args[]) {
		System.out.println("Find Valid IP v4");

		String ip1 = "10.14.15.15";
		String ip2 = "10.567.15.15";
		String ip3 = "10.0.15.15";
		String ip4 = "10.15.15";
		String ip5 = "10.15.15.12.21";

		System.out.println(isValidIPv4Address(ip1)); //true
		System.out.println(isValidIPv4Address(ip2)); //false
		System.out.println(isValidIPv4Address(ip3)); //true
		System.out.println(isValidIPv4Address(ip4)); //false
		System.out.println(isValidIPv4Address(ip5)); //false
	}

	static boolean isValidIPv4Address(String input) {

		if(input == null || input.isEmpty()) {
			return false;
		}

		String[] ips = input.split("\\.");

		if(ips.length != 4) 
			return false;

		for(String ip : ips) {
			int intip = Integer.parseInt(ip);
			if(intip < 0 || intip > 255) 
				return false;
		}

		return true;
	}
}

- ravi.pandya September 20, 2017 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

class ValidIPv4Address {

public static void main(String args[]) {
System.out.println("Find Valid IP v4");

String ip1 = "10.14.15.15";
String ip2 = "10.567.15.15";
String ip3 = "10.0.15.15";
String ip4 = "10.15.15";
String ip5 = "10.15.15.12.21";

System.out.println(isValidIPv4Address(ip1)); //true
System.out.println(isValidIPv4Address(ip2)); //false
System.out.println(isValidIPv4Address(ip3)); //true
System.out.println(isValidIPv4Address(ip4)); //false
System.out.println(isValidIPv4Address(ip5)); //false
}

static boolean isValidIPv4Address(String input) {

if(input == null || input.isEmpty()) {
return false;
}

String[] ips = input.split("\\.");

if(ips.length != 4)
return false;

for(String ip : ips) {
int intip = Integer.parseInt(ip);
if(intip < 0 || intip > 255)
return false;
}

return true;
}
}

- ravi.pandya September 20, 2017 | 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