Data Structures & AlgorithmsHardProduct Company SDE · CP practice
Problem: What is the largest possible value of gcd(a, b) when a + b = 60 and a != b with a, b positive? Run the code.
Problem: What is the largest possible value of gcd(a, b) when a + b = 60 and a != b with a, b positive? Run the code.
from math import gcd print(max(gcd(a, 60 - a) for a in range(1, 60) if a != 60 - a))What is printed?
- A. 30
- B. 15
- C. 20
- D. 60
Correct answer: C. 20
gcd(a, 60 − a) = gcd(a, 60), so a must be a multiple of the gcd; 30 needs a = b = 30, which is excluded, leaving 20 (a = 20, b = 40). 30 ignores a ≠ b, 15 is not maximal, and 60 is impossible.
More Coding Interview Problems questions
- Problem: What is the complexity of a single query in a sparse-table range minimum structure?
- Problem: What is the purpose of a 'suffix link' in Ukkonen's or Aho-Corasick's construction?
- Problem: Which property does an 'order statistics' tree support in addition to search?
- Problem: What is the time complexity of the 'Mo's algorithm with updates' (time dimension added) in terms of n and q?
- Problem: Which problem asks for the length of the shortest cycle in an undirected unweighted graph?
- Problem: Which theorem guarantees a perfect matching in a bipartite graph when Hall's condition holds for the smaller side?