ProgrammingModerateInfosys HackWithInfy · TCS CodeVita
What is printed?
What is printed?
def is_rot(a, b):
return len(a) == len(b) and b in a + a
print(is_rot('abcde', 'cdeab'), is_rot('abc', 'acb'), is_rot('', ''))- A. True False True
- B. True True True
- C. False False True
- D. True False False
Correct answer: A. True False True
A rotation appears inside the doubled string, and the length check rules out unequal lengths. cdeab appears in abcdeabcde, acb is not a rotation of abc, and two empty strings match.
More Python Programming questions
- What is printed? python def egcd(a, b): if b == 0: return a, 1, 0 g, x, y = egcd(b, a % b) return g, y, x - (a // b) y g, x, y = egcd(240…
- What is printed? python def canjump(a): far = 0 for i, x in enumerate(a): if i > far: return False far = max(far, i + x) return True…
- What is printed? python import copy a = [[1], [2]] b = a[:] c = copy.deepcopy(a) a[0].append(9) print(b, c)
- What is printed? python def f(x, acc=[]): acc.append(x) return acc f(1) f(2) print(f(3, []), f(4))
- What is printed? python def gridpaths(r, c, memo={}): if r == 0 or c == 0: return 1 if (r, c) not in memo: memo[(r, c)] = gridpaths(r - 1…
- What is printed? python def most2(s): cnt = {} l = best = 0 for r, ch in enumerate(s): cnt[ch] = cnt.get(ch, 0) + 1 while len(cnt) > 2…