Table Selection and Color Updates
Updated
Problem statement
You are given tables and a finite sequence of operations. Each row of tables is [tableId, initialColor].
Process these operations in order:
["select", tableId]makes that table the current selection.["setColor", color]changes the selected table to that color.["getColor", tableId]reads the current color of that table.
Return the colors produced by getColor operations, in operation order. Use direct table lookup so selection, update, and query each take expected O(1) time.
Function
processTableColors(tables: String[][], operations: String[][]) → String[]Examples
Example 1
tables = [["users","white"],["orders","gray"]]operations = [["select","users"],["setColor","blue"],["getColor","users"],["getColor","orders"]]return = ["blue","gray"]The update changes only users. The two queries then return blue and gray.
Example 2
tables = [["a","red"],["b","green"]]operations = [["select","a"],["setColor","black"],["select","b"],["setColor","white"],["getColor","a"],["getColor","b"]]return = ["black","white"]Changing the selection directs each update to a different table.
Example 3
tables = [["only","orange"]]operations = [["getColor","only"],["select","only"],["setColor","orange"],["getColor","only"]]return = ["orange","orange"]A query works before any selection, and setting the existing color leaves the value unchanged.
Constraints
1 <= tables.length <= 200000.1 <= operations.length <= 200000.- Table identifiers are unique, and every referenced table exists.
- Every
setColoroccurs after aselect. - Identifiers and colors are non-empty strings containing at most
50characters.
More Figma Onsite Interview questions
- Recursive Display SortPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Rich Text Parser Part 3 (Depth Tokens)PHONE SCREEN · ONSITE INTERVIEW · Seen Oct 2026
- Rich Text Parser Part 2 (Parse Nested Groups)PHONE SCREEN · ONSITE INTERVIEW · Seen Oct 2026
- Rich Text Parser Part 1 (Validate Tokens)PHONE SCREEN · ONSITE INTERVIEW · Seen Oct 2026
- Sort Documents Left to RightONSITE INTERVIEW · Seen Aug 2026
- Symmetric Binary TreeONSITE INTERVIEW · Seen Feb 2026
- Topmost Accessible NodesPHONE SCREEN · ONSITE INTERVIEW · Seen Jan 2025
- Nested Template Variable ExpansionONSITE INTERVIEW · Seen Jun 2024
- Parse, Validate, and Repair Markdown FormattingONSITE INTERVIEW · Seen Jun 2024
- Breadth-First Values of a Binary TreeONSITE INTERVIEW · Seen Oct 2022
Similar questions at other companies
- Config Store with Priority OverridesMicrosoft · PHONE SCREENMicrosoft interview questions
- ID Allocator with Assign and ReleaseSnap Inc. · PHONE SCREENSnap Inc. interview questions
- Portfolio Valuation, Part 1Stripe · PHONE SCREENStripe interview questions
- Feature Flag EvaluationCVS Health · PHONE SCREEN
- Count Distinct Underwriting PII ValuesAffirm · PHONE SCREEN · ONSITE INTERVIEWAffirm interview questions
- Network Endpoint or Cycle BoundaryOpenAI · OA · PHONE SCREENOpenAI interview questions
- Bounded IPv4 FilterAmazon · PHONE SCREEN
- Basic In-Memory SpreadsheetGoogle · ONSITE INTERVIEWGoogle interview questions
- SimpleRDD Multiset IntersectionDatologyAI · PHONE SCREEN
- Policy Violation Set ChecksPinterest · ONSITE INTERVIEWPinterest interview questions