PracHub
QuestionsPremiumCoachesLearningGuidesInterview Prep
|Home/Coding & Algorithms/Salesforce

Implement common data-structure and JS tasks

Last updated: Mar 29, 2026

Quick Overview

This multi-part prompt evaluates core competencies in data structures and algorithms (time-based key-value design, duplicate removal in sorted linked lists), JavaScript language features (currying and value coercion), and frontend asynchronous control flow (timers, Promises/async-await).

  • medium
  • Salesforce
  • Coding & Algorithms
  • Software Engineer

Implement common data-structure and JS tasks

Company: Salesforce

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: medium

Interview Round: Onsite

You are given several independent coding tasks that appeared across an OA and frontend-focused interviews. Implement each as specified. ## 1) Time-based key-value store Design a data structure that supports storing multiple values for the same key at different timestamps. ### Operations - `set(key: string, value: string, timestamp: int) -> void` - `get(key: string, timestamp: int) -> string` ### `get` rule Return the value associated with `key` at the **largest** timestamp `t` such that `t <= timestamp`. If no such timestamp exists for that key, return an empty string. ### Constraints (typical) - Many calls; aim for ~`O(log n)` per `get` per key. - Timestamps for a given key are non-decreasing across `set` calls. --- ## 2) Remove duplicates from a linked list Given the head of a **sorted** singly linked list, remove duplicates so that each value appears only once. - Input: `head` of a sorted list. - Output: the modified list head. Example: `1 -> 1 -> 2 -> 3 -> 3` becomes `1 -> 2 -> 3`. --- ## 3) Implement a curried “add” function in JavaScript Implement a JavaScript function `add` that supports chained calls via currying. ### Required behavior (pick one clear contract and implement it) Option A (explicit terminator): - `add(1)(2)(3)()` returns `6`. Option B (implicit coercion): - `add(1)(2)(3) == 6` is `true` (via `valueOf`/`toString`). Handle common edge cases (e.g., `add(0)`, negative numbers). --- ## 4) Traffic light scheduler (frontend async) Implement a function that repeatedly cycles through traffic lights in order: - Red for 3 seconds - Green for 2 seconds - Yellow for 1 second Requirements: - The sequence must repeat indefinitely (or for `n` cycles if you choose to add a parameter). - Use asynchronous control flow (Promises / `async`/`await` / timers). - Each transition should trigger a callback/log such as `console.log('red')` at the moment the light turns on.

Quick Answer: This multi-part prompt evaluates core competencies in data structures and algorithms (time-based key-value design, duplicate removal in sorted linked lists), JavaScript language features (currying and value coercion), and frontend asynchronous control flow (timers, Promises/async-await).

Related Interview Questions

  • Solve Two OA Coding Problems - Salesforce (medium)
  • Maximize events attended given date ranges - Salesforce (medium)
  • Minimize operations to reduce integer to zero - Salesforce (medium)
  • Implement an LFU cache with O(1) operations - Salesforce (medium)
  • Flatten a nested JSON object - Salesforce (medium)
Salesforce logo
Salesforce
Feb 12, 2026, 12:00 AM
Software Engineer
Onsite
Coding & Algorithms
6
0
Loading...

You are given several independent coding tasks that appeared across an OA and frontend-focused interviews. Implement each as specified.

1) Time-based key-value store

Design a data structure that supports storing multiple values for the same key at different timestamps.

Operations

  • set(key: string, value: string, timestamp: int) -> void
  • get(key: string, timestamp: int) -> string

get rule

Return the value associated with key at the largest timestamp t such that t <= timestamp. If no such timestamp exists for that key, return an empty string.

Constraints (typical)

  • Many calls; aim for ~ O(log n) per get per key.
  • Timestamps for a given key are non-decreasing across set calls.

2) Remove duplicates from a linked list

Given the head of a sorted singly linked list, remove duplicates so that each value appears only once.

  • Input: head of a sorted list.
  • Output: the modified list head.

Example: 1 -> 1 -> 2 -> 3 -> 3 becomes 1 -> 2 -> 3.

3) Implement a curried “add” function in JavaScript

Implement a JavaScript function add that supports chained calls via currying.

Required behavior (pick one clear contract and implement it)

Option A (explicit terminator):

  • add(1)(2)(3)() returns 6 .

Option B (implicit coercion):

  • add(1)(2)(3) == 6 is true (via valueOf / toString ).

Handle common edge cases (e.g., add(0), negative numbers).

4) Traffic light scheduler (frontend async)

Implement a function that repeatedly cycles through traffic lights in order:

  • Red for 3 seconds
  • Green for 2 seconds
  • Yellow for 1 second

Requirements:

  • The sequence must repeat indefinitely (or for n cycles if you choose to add a parameter).
  • Use asynchronous control flow (Promises / async / await / timers).
  • Each transition should trigger a callback/log such as console.log('red') at the moment the light turns on.

Submit Your Answer

Sign in to leave a comment

Loading comments...

Browse More Questions

More Coding & Algorithms•More Salesforce•More Software Engineer•Salesforce Software Engineer•Salesforce Coding & Algorithms•Software Engineer Coding & Algorithms
PracHub

Master your tech interviews with 8,500+ real questions from top companies.

Product

  • Questions
  • Learning Tracks
  • Interview Guides
  • Resources
  • Premium
  • For Universities
  • Student Access

Browse

  • By Company
  • By Role
  • By Category
  • Topic Hubs
  • SQL Questions
  • Compare Platforms
  • Discord Community

Support

  • support@prachub.com
  • (916) 541-4762

Legal

  • Privacy Policy
  • Terms of Service
  • About Us

© 2026 PracHub. All rights reserved.