StartUp Interview Question for Java Developers


Country: India
Interview Type: Written Test




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

/* 
Observe that the problem is that of finding locations where 
we can cut the string.
Given a string of length 's' has exact s-1 locations where we can cut it 
That s-1 becomes the number of choices = n.
Clearly then the number of comma = k is the cut locations to be selected.
It is obvious that the order in which the cut was imposed does not matter.
Thus, the choices are C(n,k).
Thus, the problem is:
1. finding combinations of cut
2. Applying the cuts 
3. Maintaining a max out of the cuts
*/

def do_fancy(string, k){
    n = size(string) - 1
    range = [0:k+1]
    max = 0
    for ( t : comb(range,k) ){
        start_inx = 0
        words = list()
        for ( i = 0; i < k ; i+= 1 ){
          words += int( string[start_inx:t[i]] )
          start_inx = t[i] + 1
        }
         words += int( string[start_inx:-1] )
        #(m,M) = minmax( words )
        #(m,max) = minmax( max, M )
    }
    max // return 
}

println( do_fancy( '89769957',3 ) )

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

Code in Python. Works for all above inputs.

#s = '999'
#k = 1
#output = 9,99 or 99,9 : 99
#s = '999'
#k = 2
#output = 9,9,9 : 9
s = '857'
k = 1
#output = 8,57 or 85,7 : 85

def check(s,k):
	len1 = len(s)
	if len1 <= k:
		return None

	#pointer = len1/(k+1)
	#print pointer

	list1 = []
	s1 = ''
	s2 = ''
	for i in range (0,k):
		list1.append(s[i])
	
	for i in range (k,len1):
		s1 = s1 + s[i]

	list1.append(s1)

	for i in range(len1-1,len1-1-k,-1):
		list1.append(s[i])

	for i in range(0,len1-k):
		s2 = s2+s[i]


	list1.append(s2)

	temp = 0

	for items in list1:
		intitems = int(items)
		if intitems > temp:
			temp = intitems

	return temp




highest = check(s,k)
print highest

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

#!usr/bin/env python
import sys

def listStrings(string, numofcommas):
i = numofcommas
while i < len(string):
string = string[:i] + ',' + string[i:]
i = i + 1
i = i + numofcommas
print(string)
string_list.append(string)
return string_list


def preCheck(string, numofcommas):
if len(string) <= numofcommas:
print "Given String ' {} ' length is less than that of numberof commas hence can't be splitted".format(string)
sys.exit()
else:
listStrings(string,numofcommas)
rev_str = string[::-1]
listStrings(rev_str,numofcommas)

def checkgreatest(str_list):
greatest_num = 0
for i in str_list:
#print i
#print type(i)
mini_list = i.split(',')
#print mini_list
if max(mini_list) > greatest_num:
greatest_num = max(mini_list)
print "{} is the highest Number among the {} list".format(greatest_num,str_list)
return greatest_num

if __name__ == '__main__':
string_list = []
#string = raw_input("Enter the numeric string")
str_list = preCheck("12345674",1)
checkgreatest(string_list)

- Dayananda D R February 11, 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