Interview Question


Country: United States




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

Python. The code works fine with all inputs and edge cases.

#Input: 
#inputString = awaglk 
#num = 4 
#Output: 
#[awag] 

def take_input():
	s1 = raw_input("Please Enter the String :")

	k = raw_input("Please enter the number :")
	k = int(k)
	if k <= 0 or k > 26 :
		while k <= 0 or k > 26 :
			k = raw_input("Please enter the number :")
			k = int(k)

	final = check(s1,k)
	return final


def check(s1,k):
	len1 = len(s1)
	list1 = []
	if k > len1:
		return list1

	for i in range (0,len1-k+1):
		temp = ''
		for j in range (i, i+k):
			temp = temp + s1[j]
		list1. append(temp)

	final = [] 

	for items in list1:
		dict1 = {}
		for i in range(0,k):
			if items[i] in dict1:
				dict1[items[i]] += 1
			else:
				dict1[items[i]] = 0
		sum = 0
		for values in dict1.values():
			sum = sum + values
		if sum == 1:
			final.append(items)

	return final


final = take_input()
print final

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

I wrote the code in Python. Works for all inputs and edge cases.

#Input: 
#inputString = awaglk 
#num = 4 
#Output: 
#[awag] 

def take_input():
	s1 = raw_input("Please Enter the String :")

	k = raw_input("Please enter the number :")
	k = int(k)
	if k <= 0 or k > 26 :
		while k <= 0 or k > 26 :
			k = raw_input("Please enter the number :")
			k = int(k)

	final = check(s1,k)
	return final


def check(s1,k):
	len1 = len(s1)
	list1 = []
	if k > len1:
		return list1

	for i in range (0,len1-k+1):
		temp = ''
		for j in range (i, i+k):
			temp = temp + s1[j]
		list1. append(temp)

	final = [] 

	for items in list1:
		dict1 = {}
		for i in range(0,k):
			if items[i] in dict1:
				dict1[items[i]] += 1
			else:
				dict1[items[i]] = 0
		sum = 0
		for values in dict1.values():
			sum = sum + values
		if sum == 1:
			final.append(items)

	return final


final = take_input()
print final

- koolkhush February 12, 2018 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

@koolkhuch Thanks a lot

- Bonsavic Petro February 13, 2018 | 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