Problem 502077 · easy · Phase 05 Advanced Algorithms & Graphs

Widest Tile That Fits Every Wall

number theory · gcd · Euclid's algorithm

A tiler wants square tiles of one width t that cover every wall exactly with whole tiles laid in a row, so t must divide every wall length in walls. Return the largest such t. Walls of length 0 need no tiles and impose no condition; if there are no positive walls, return 0. Write Euclid's algorithm yourself.

Examples

Input:  walls = [12, 18, 30]
Output: 6
Input:  walls = [7, 0]
Output: 7

Constraints

  • 0 <= len(walls) <= 10**5, 0 <= walls[i] <= 10**18.
  • Target complexity: O(n log(max)).

Goals

  • Implement Euclid's algorithm with remainders
  • Fold the gcd across a whole list
Starting Python…