FastPrepFarthest Affordable Shop per Query
Problems/Farthest Affordable Shop per Query

Farthest Affordable Shop per Query

Adobe logoAdobe● MediumFULLTIMEONSITE INTERVIEW

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: The report gives the ordered shop costs, the budget queries, the goal of reaching the farthest shop, and the prefix-sum plus binary-search direction. We chose the index convention and the limits. Our version is about 96% the same as the reported question.

A street has an ordered array shopCosts, where shopCosts[i] is the amount required to visit shop i.

Each row of queries is [start, budget]. Begin at the zero-based shop start and visit consecutive shops to the right. Visiting a shop spends its cost, including the starting shop.

For each query, return the farthest shop index you can visit without spending more than budget. Return -1 when the starting shop itself is unaffordable. Each query is independent.

Function

farthestAffordableShops(shopCosts: int[], queries: int[][]) → int[]

Examples

Example 1

shopCosts = [2,4,1,3]queries = [[0,7],[1,4],[2,10],[3,2]]return = [2,1,3,-1]

The first query spends 2 + 4 + 1 and reaches shop 2. The last budget cannot pay the cost at shop 3.

Example 2

shopCosts = [1,1,1]queries = [[0,2],[1,2]]return = [1,2]

A budget of 2 pays for two consecutive unit-cost shops from either starting point.

Constraints

  • 1 <= shopCosts.length <= 100000
  • 1 <= queries.length <= 100000
  • 0 <= shopCosts[i] <= 10^9
  • Each query is [start, budget], where 0 <= start < shopCosts.length and 0 <= budget <= 10^9.
  • Use signed 64-bit arithmetic for prefix sums.

More Adobe interview questions

  • Binary Tree Level-Order Traversal by LevelsPHONE SCREEN · ONSITE INTERVIEW · Seen Aug 2026
  • Lowest Common Ancestor Only When Both Targets ExistONSITE INTERVIEW · Seen Aug 2026
  • Lowest Common Ancestor with Parent PointersONSITE INTERVIEW · Seen Aug 2026
  • Next and Previous Lexicographic PermutationONSITE INTERVIEW · Seen Aug 2026
  • Asteroid CollisionONSITE INTERVIEW · Seen Aug 2026
  • Minimum Removals for a Nice ArrayONSITE INTERVIEW · Seen Aug 2026
  • Count Occurrences in a Sorted ArrayPHONE SCREEN · ONSITE INTERVIEW · Seen Jul 2026
  • Trie: Add and Search WordsONSITE INTERVIEW · Seen Jul 2026
  • Base Unit ConversionsOA · Seen Nov 2026
  • Evaluate a Parenthesized Integer ExpressionPHONE SCREEN · Seen Oct 2026

Similar questions at other companies

  • Totals from a Tiered Rate TableMicrosoft · ONSITE INTERVIEWMicrosoft interview questions
  • Random Pick with Weight Using Recorded DrawsGoogle · PHONE SCREEN · ONSITE INTERVIEWGoogle interview questions
  • Random Pick with Weight Using Recorded DrawsAmazon · ONSITE INTERVIEW
  • Multinomial Sampling with Distribution ChecksNVIDIA · ONSITE INTERVIEWNVIDIA interview questions
  • Weighted Random Key SelectionRoblox · ONSITE INTERVIEWRoblox interview questions
  • Shortest Subarray with Sum at Least KOracle · ONSITE INTERVIEWOracle interview questions
  • Roll a Weighted DieLinkedIn · ONSITE INTERVIEWLinkedIn interview questions
  • Count Lamps Lighting Each PointAirbnb · OAAirbnb interview questions
  • Choose ContainersIMC Trading · OAIMC Trading interview questions
  • Good Ways to Split an ArraySalesforce · PHONE SCREENSalesforce interview questions

Interview reports that mention this question

  • Adobe Android Engineer Round 1: 3 Experiences (Part 10 of 12)

Adobe interview experiences

  • Adobe New Grad OA: Unit Conversion and Code Review: 1 Experience
  • Adobe Web, QA, DevOps, ML Roles: 13 Experiences (Part 3 of 3)
  • Adobe SWE Interviews, Level Unknown: 25 Experiences (Part 2 of 3)
  • Adobe Interviews, Level Unknown: 38 Experiences (Part 1 of 3)
  • Adobe New Grad MTS Interview Questions: 7 Experiences
All Adobe interview questionsSee Adobe hiring insights
Saved
class Solution {
    public int[] farthestAffordableShops(int[] shopCosts, int[][] queries) {
        // Write your code here.
    }
}
Checking account…