2dbi
Home/ServiceNow/Implement a Stack Using Queues + Producer-Consumer
SServiceNow·DSAIC2Onsite – Coding 1

Implement a Stack Using Queues + Producer-Consumer

Problem

Implement a LIFO stack using only queue operations, then implement a thread-safe producer-consumer.

Example

push/pop/top/empty using two queues; bounded buffer with mutex+condvar

Constraints

  • Producer-consumer must be race-free

What ServiceNow looks for

Both were reported. Discuss the push-costly vs pop-costly trade-off, and condition variables for producer-consumer.

added 6 days ago
LeadersAccount