FastPrepCompetitive Foraging
Problems/Competitive Foraging

Competitive Foraging

Akuna Capital logoAkuna Capital● HardNEW GRADINTERNOA

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: The screenshot hides some of the rules for accepting answers and some limits.

Our version is about 85% the same as the reported question.

Special thanks: 🌷 A special thank you to our lovely, amazing frenz for sharing a similar interview question, with reported date of September 13, 2026! ദ്ദി ˉ͈̀꒳ˉ͈́ )✧ 💜

You and a deterministic rival forage for food on a 15-by-15 grid. You move first in every round, then the rival moves if food remains. Each food cell is worth one point to whichever forager reaches it first. The game ends as soon as all food has been eaten.

Grid cells

  • . is an empty cell.
  • # is a wall.
  • P is your starting cell.
  • O is the rival's starting cell.
  • F is a food cell.

Your move

Choose one of U, D, L, R, or S for up, down, left, right, or stay. A move is valid only when its destination remains on the grid, is not a wall, and is not the rival's current cell. If you enter a food cell, you eat that food and score one point.

The rival's move

If food remains after your move, the rival takes one step toward the nearest food it can reach without entering a wall or your current cell. Distances are unweighted BFS distances. Among legal adjacent steps that attain the smallest distance to any remaining food, the rival chooses the first in this order: up, down, left, right. If no food is reachable, the rival stays. If the rival enters a food cell, it eats that food and scores one point.

Required result

Return the shortest valid move string that ends the game with your score strictly greater than the rival's score. Among equal-length winning strings, return the first string under the move-priority order U, D, L, R, S. Do not include moves after the game ends.

For this exercise, assume the game stops immediately when you eat the final food, before the rival would move in that round. A winning sequence is guaranteed to exist.

Function

competitiveForaging(grid: String[]) → String

Examples

Example 1

grid = ["###############","#PFO###########","###############","###############","###############","###############","###############","###############","###############","###############","###############","###############","###############","###############","###############"]return = "R"

Move right onto the only food cell. Your score becomes 1, the rival's score remains 0, and the game ends before the rival moves. No winning string can be shorter than one move.

Example 2

grid = ["###############","#..F.P#########","#....O#########","#...F.#########","#FF...#########","###############","###############","###############","###############","###############","###############","###############","###############","###############","###############"]return = "LDLSUDDDLL"

The rival eats the food at row 3, column 4 after the second player move. The stay move on turn 4 lets the rival leave the route to the upper food. You then eat the upper food and both lower foods, finishing with scores 3 to 1. Exhaustive breadth-first search finds no shorter winning string, and this is the first winning string at length 10 under the required move order.

Constraints

  • grid.length == 15.
  • grid[r].length == 15 for every row r.
  • Every cell is one of ., #, P, O, or F.
  • There is exactly one P, exactly one O, and between 1 and 6 food cells.
  • There are at most 30 non-wall cells.
  • At least one valid winning move string exists.

More Akuna Capital Online Assessment questions

  • Delivery Management SystemOA · Seen Nov 2026
  • Count Server ReplacementsOA · Seen Nov 2026
  • Match Orders by Price and Arrival TimeOA · PHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Maximum Remaining Drone PowerOA · Seen Nov 2026
  • Rolling MetricsOA · Seen Oct 2026
  • Vowel Substring GameOA · Seen Sep 2026
  • Binary CircuitOA · Seen Sep 2026
  • Items SortOA · Seen Sep 2026
  • Minimize Malware Spread by Removing a NodeOA · Seen Sep 2026
  • K Smallest SubstringOA · Seen Sep 2026

Similar questions at other companies

  • Escape the Haunted Castle with TreasuresPersona · OAPersona interview questions
  • Safest Shortest Path Through a GridSnowflake · OASnowflake interview questions
  • Drone Delivery with Battery Swap StationsCisco · OACisco interview questions
  • Minimum MovesHarness · OA
  • Shortest Path Around Rectangular ObstaclesDRW · OADRW interview questions
  • Minimum Knight MovesMcKinsey & Company · OAMcKinsey & Company interview questions
  • Simulate Orchard Rot SpreadZipRecruiter · OAZipRecruiter interview questions
  • Minimum MovesGoldman Sachs · OAGoldman Sachs interview questions
  • Grid ExplorationIMC Trading · OAIMC Trading interview questions
  • Shortest Grid Path with Obstacle EliminationsAmazon · ONSITE INTERVIEW

Akuna Capital interview experiences

  • Akuna Capital Quant Trader and QR Interviews: 5 Experiences
  • Akuna Capital JQR CodePair Rounds: 8 Experiences (Part 6 of 6)
  • Akuna Capital QR Probability Phones: 14 Experiences (Part 5 of 6)
  • Akuna Capital QR-ML Interviews: 11 Experiences (Part 4 of 6)
  • Akuna Capital QR Regression Rounds: 11 Experiences (Part 3 of 6)
  • Akuna Capital QR Coding Interviews: 17 Experiences (Part 2 of 6)
All Akuna Capital interview questionsSee Akuna Capital hiring insights
Saved
class Solution {
    public String competitiveForaging(String[] grid) {
        // Write your code here.
    }

}
Checking account…