FastPrepResource Reconciler: Plan and Apply Creates
Problems/Resource Reconciler: Plan and Apply Creates

Resource Reconciler: Plan and Apply Creates

Perplexity AI logoPerplexity AI● MediumFULLTIMEPHONE SCREEN

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: The report describes a long six-part phone-screen question about a resource reconciler, much like an infrastructure-as-code tool. The author reached part 2 but did not finish it. Part 1 plans which resources must be created, and part 2 creates them, saves the new bindings and has to pass a failed call back to the caller. Parts three to six were not described.

The report shows attributes as a small key-value map but gives no runnable format, and it does not say which ids new resources get, how an error is shown, or what to do when the bound resource still exists. Here one part argument picks plan or apply, and attributes are one text value copied as is. Plan lines carry no resource id. An existing resource needs no change, and updates and deletes are out of scope. Addresses sort as plain strings. The k-th create returns res-k, and no input id starts with res-. Apply returns the whole final store sorted by address, including bindings outside the wanted list. A failed create stops the run and saves nothing for that change, so its old binding and all earlier new bindings stay, and an ERROR line naming the address comes last. You get the inputs and the client calls as lists and a call number instead of the original classes.

Our version covers the two parts the author reached and is about 75% the same as the reported question.

A resource reconciler compares the configuration you want with what really exists, then makes the changes needed to close the gap. You will build its first two parts.

Three inputs describe the world:

  • desired maps a logical address to the attributes you want. Each row is [address, attributes].
  • state is the saved state. Each row is a binding [address, resourceId, attributes]: the resource that the address was last bound to, and its attributes at that time.
  • remote lists the resource ids that the resource client can find. client.read(resourceId) returns the resource when its id is in remote, and nothing otherwise.

Attributes are one text value, such as replicas=3. Copy them exactly; never parse or merge them.

Part 1: Plan the creates (part = "plan")

Go through the addresses in desired in sorted order. Compare addresses as plain strings, character by character. For each address:

  • If state has no binding for it, it needs a CREATE change. There is no resource id to read, so do not call the client.
  • If it has a binding but client.read finds nothing for the bound resource id, the resource is gone and it needs a CREATE change.
  • If the bound resource exists, it needs no change in this problem, even when its attributes differ. Updates and deletes belong to later parts that are not covered here.

Return one line per change, in plan order: "CREATE <address> <attributes>", using the attributes from desired.

Part 2: Apply the creates (part = "apply")

Build the same plan, then run its changes in order. For each change:

  1. Call client.create(attributes). The k-th create call returns a new resource with id res-k (res-1, res-2, and so on).
  2. Save the binding [address, newId, attributes] in the state store with put. It inserts a new binding or replaces the old binding for that address.

A change is done only when its resource was created and its binding was saved. If failAt is not 0, the create call number failAt throws an error instead of returning. The error must go back to the caller: stop at once, save nothing for that change, and run no later change. Bindings saved by earlier changes stay saved.

Return the final state store, one line per binding sorted by address: "<address> <resourceId> <attributes>". Bindings for addresses that are not in desired stay as they are. If a create call threw, add one more line at the end: "ERROR <address>", naming the change that failed.

Function

reconcile(part: String, desired: String[][], state: String[][], remote: String[], failAt: int) → String[]

Examples

Example 1

part = "plan"desired = [["search_api","replicas=3"]]state = [["search_api","r-123","replicas=1"]]remote = []failAt = 0return = ["CREATE search_api replicas=3"]

The state binds search_api to resource r-123, but the client cannot find r-123, so the resource is missing and must be created with the desired attributes replicas=3.

Example 2

part = "plan"desired = [["web","replicas=2"],["cache","size=4"],["db","tier=gold"]]state = [["db","r-7","tier=gold"],["web","r-9","replicas=1"]]remote = ["r-7"]failAt = 0return = ["CREATE cache size=4","CREATE web replicas=2"]

The addresses are checked in sorted order: cache, db, web. cache has no binding in the state, so it is created without asking the client. db is bound to r-7, which the client finds, so it needs no change. web is bound to r-9, which the client cannot find, so it is created. The plan is cache, then web.

Example 3

part = "apply"desired = [["web","replicas=2"],["cache","size=4"],["db","tier=gold"]]state = [["db","r-7","tier=gold"],["web","r-9","replicas=1"]]remote = ["r-7"]failAt = 0return = ["cache res-1 size=4","db r-7 tier=gold","web res-2 replicas=2"]

The same inputs, now applied. The plan creates cache first, and the client returns res-1; then web gets res-2. Each new binding is saved, so web's old binding to r-9 is replaced. db keeps its binding. The final state is listed by address.

Example 4

part = "apply"desired = [["web","replicas=2"],["cache","size=4"],["db","tier=gold"]]state = [["db","r-7","tier=gold"],["web","r-9","replicas=1"]]remote = ["r-7"]failAt = 2return = ["cache res-1 size=4","db r-7 tier=gold","web r-9 replicas=1","ERROR web"]

This time the second create call fails. cache was already created as res-1 and saved, so it stays. The failure happens while creating web, so its binding is not saved and the old binding to r-9 is still there. The error goes back to the caller and nothing after it runs, so the last line is ERROR web.

Constraints

  • part is "plan" or "apply".
  • 1 <= desired.length <= 50 and each desired[i] has 2 strings.
  • 0 <= state.length <= 50 and each state[i] has 3 strings.
  • 0 <= remote.length <= 50
  • An address is 1 to 20 characters: a lowercase letter followed by lowercase letters, digits or underscores. Addresses in desired are distinct, and so are addresses in state.
  • An attributes value is 1 to 30 characters from lowercase letters, digits, _, = and ,.
  • A resource id is 1 to 12 characters: a lowercase letter followed by lowercase letters, digits or -. Ids in remote are distinct. No id in state or remote starts with res-.
  • 0 <= failAt <= 50, and failAt == 0 when part is "plan".

More Perplexity AI interview questions

  • In-Memory Filesystem CommandsPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Agent Task Dependency TrackerPHONE SCREEN · Seen May 2026
  • LLM Provider Pool FailoverPHONE SCREEN · Seen Aug 2025
  • Out-of-Order Bank Ledger BalancesOA · Seen Nov 2026
  • Feature Flags with Rules, Dependencies and ExposureONSITE INTERVIEW · Seen Nov 2026
  • Sort Topic Names by Prefix and NumberONSITE INTERVIEW · Seen Oct 2026

Similar questions at other companies

  • Pins Violation Log QueriesPinterest · PHONE SCREENPinterest interview questions
  • Resolve Visible User FeaturesStripe · PHONE SCREENStripe interview questions
  • Credit Card Command ProcessorChime · PHONE SCREEN
  • Popular and Instant-Runoff Election WinnersCoursera · PHONE SCREEN
  • AI Role: Collection with Add and Remove OperationsApple · PHONE SCREENApple interview questions
  • Read a File from Distributed ChunksHudson River Trading · ONSITE INTERVIEWHudson River Trading interview questions
  • HTTP Request RedirectionAmazon · OA
  • P&L Leaderboard OperationsBloomberg LP · ONSITE INTERVIEWBloomberg LP interview questions
  • Aggregate Paginated Project Run RecordsReplit · OA
  • Parcel Attribute Store with TTLAirbnb · OAAirbnb interview questions
All Perplexity AI interview questionsSee Perplexity AI hiring insights
Saved
class Solution {
    public String[] reconcile(String part, String[][] desired, String[][] state, String[] remote, int failAt) {
        // Write your code here.
    }
}
Checking account…