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``````

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``````

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

@koolkhuch Thanks a lot

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.

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.