← Agoda Interview Insights

Agoda·Software Engineer·Technical Phone Screen·Intermediate

Intermediate
Jun 2026

Summary

Agoda coding interview with a dynamic programming problem on triangle path sums. Pretty standard algorithmic question but still worth thinking through carefully before diving in.

Questions Asked (1)

Q1

Given a triangle represented as a 2D array, find the minimum path sum from the top to the bottom row, where at each step you can only move to adjacent numbers in the row below.

Algorithms & Data Structures
Author's notes

Classic DP problem but I second-guessed myself on the adjacency definition for a bit.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Start by clarifying the problem constraints and edge cases, then propose a dynamic programming solution that computes the minimum path sum in O(n^2) time and O(n) space. Explain how you can optimize space by updating the triangle in place or using a 1D array, and walk through a small example to demonstrate correctness.

Pro tip: Mention that you can solve it in-place by modifying the input triangle to store cumulative sums, which shows awareness of space optimization. Also, discuss how the problem relates to real-world scenarios like finding the cheapest path in a cost matrix, which can impress interviewers at product companies like Agoda.

1. Clarify the problem

Ask about input constraints (e.g., triangle size, value ranges), whether the triangle is mutable, and if negative numbers are allowed. Confirm that adjacent means indices i and i+1 in the next row.

2. Define the DP state

Let dp[i][j] be the minimum path sum from the top to position (i, j). The recurrence is dp[i][j] = triangle[i][j] + min(dp[i-1][j-1], dp[i-1][j]) with boundary conditions.

3. Optimize space

Instead of a 2D DP table, use a 1D array or modify the triangle in place. Update from bottom to top or top to bottom carefully to avoid overwriting needed values.

4. Implement and test

Write clean code, handle edge cases (e.g., empty triangle, single row), and test with a small example. Analyze time and space complexity: O(n^2) time, O(n) space (or O(1) extra if in-place).

5. Discuss trade-offs

Compare top-down vs bottom-up DP, and mention that bottom-up avoids boundary checks. Also, note that if the triangle is large, in-place modification might not be allowed, so discuss alternatives.

Key Points to Mention

  • Dynamic programming approach with optimal substructure
  • Time complexity O(n^2) and space complexity O(n) or O(1) extra
  • In-place modification of the triangle to save space
  • Handling edge cases like empty input or single row
  • Bottom-up vs top-down DP and why bottom-up is simpler
  • Relation to real-world pathfinding or cost minimization problems

AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.