FastPrepStock System with Updates and Percentage Change
Problems/Stock System with Updates and Percentage Change

Stock System with Updates and Percentage Change

Lead Bank logoLead Bank● MediumONSITE INTERVIEW

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: Reported in a Lead Bank onsite interview. The report gives the record model and the main operations. It does not give the exact output format, what to do when a record is missing, how markers start and end, how precise the percentage is, how to break ties, or the limits. We chose those. Our version is about 88% the same as the reported question.

Implement a stock-record system. Each initial row in records is [ticker, date, price], where price is a positive integer written as a decimal string. A record is uniquely identified by its ticker and ISO date.

Every initial record has an updated marker set to false. Process each row in operations and append one result string:

  • ["GET", ticker, date]: Return price|updated, such as 12500|true. Reading does not change the marker.
  • ["UPDATE", ticker, date, newPrice]: Replace the price, set updated to true, and return newPrice|true.
  • ["PERCENTAGE_CHANGE", ticker, startDate, endDate]: Compute (endPrice - startPrice) * 100 / startPrice. Truncate toward zero to two decimal places and return exactly two digits after the decimal followed by %.
  • ["BETTER_PERFORMER", firstTicker, secondTicker, startDate, endDate]: Return the ticker with the larger percentage change over those dates. If both changes are equal, return the lexicographically smaller ticker.

If an operation needs any record that does not exist, append NOT_FOUND and do not change state. Percentage comparison uses the exact ratio rather than the displayed two-decimal value. Return all result strings in operation order.

Function

processStockOperations(records: String[][], operations: String[][]) → String[]

Examples

Example 1

records = [["AAPL","2026-01-02","10000"],["AAPL","2026-01-03","12500"],["MSFT","2026-01-02","20000"],["MSFT","2026-01-03","22000"]]operations = [["GET","AAPL","2026-01-02"],["UPDATE","AAPL","2026-01-02","11000"],["GET","AAPL","2026-01-02"],["PERCENTAGE_CHANGE","AAPL","2026-01-02","2026-01-03"],["BETTER_PERFORMER","AAPL","MSFT","2026-01-02","2026-01-03"],["GET","GOOG","2026-01-02"]]return = ["10000|false","11000|true","11000|true","13.63%","AAPL","NOT_FOUND"]

The update changes AAPL's starting price to 11000 and permanently sets that record's marker. Its percentage change is (12500 - 11000) * 100 / 11000, truncated to 13.63%, which is greater than MSFT's 10.00%. The GOOG record is absent.

Example 2

records = [["AAA","2026-02-01","100"],["AAA","2026-02-02","90"],["BBB","2026-02-01","200"],["BBB","2026-02-02","180"]]operations = [["PERCENTAGE_CHANGE","AAA","2026-02-01","2026-02-02"],["BETTER_PERFORMER","BBB","AAA","2026-02-01","2026-02-02"],["UPDATE","CCC","2026-02-01","50"],["GET","BBB","2026-02-01"]]return = ["-10.00%","AAA","NOT_FOUND","200|false"]

Both stocks lose exactly 10.00%, so the comparison returns the lexicographically smaller ticker AAA. Updating a missing record returns NOT_FOUND, and the untouched BBB record still has marker false.

Constraints

  • 1 <= records.length <= 10^4
  • 1 <= operations.length <= 10^4
  • Each initial (ticker, date) key is unique.
  • Every ticker is a non-empty uppercase ASCII string, and every date uses YYYY-MM-DD.
  • Every initial and updated price is an integer in [1, 10^9].
  • Every operation has one of the documented shapes.

More Lead Bank Onsite Interview questions

  • Calendar Event System with Pagination and IntersectionONSITE INTERVIEW · Seen Jul 2026

Similar questions at other companies

  • Pro-Rata Order BookIMC Trading · ONSITE INTERVIEWIMC Trading interview questions
  • Rectangle Point Coverage CountsOpenAI · PHONE SCREEN · ONSITE INTERVIEWOpenAI interview questions
  • Transactional Key-Value StoreGrammarly · ONSITE INTERVIEW
  • LRU CacheApple · PHONE SCREEN · ONSITE INTERVIEWApple interview questions
  • LRU Cache for Query ResultsAmazon · PHONE SCREEN · ONSITE INTERVIEW
  • Random Dasher Set OperationsDoorDash · ONSITE INTERVIEWDoorDash interview questions
  • File System Shell CommandsHarvey · ONSITE INTERVIEWHarvey interview questions
  • In-Memory Filesystem CommandsPerplexity AI · PHONE SCREEN · ONSITE INTERVIEWPerplexity AI interview questions
  • LRU CacheServiceNow · PHONE SCREEN · ONSITE INTERVIEWServiceNow interview questions
  • Hash Map with Separate ChainingApplied Intuition · ONSITE INTERVIEWApplied Intuition interview questions
All Lead Bank interview questionsSee Lead Bank hiring insights
Saved
class Solution {
    public String[] processStockOperations(String[][] records, String[][] operations) {
        // write your code here
    }
}
Checking account…