Implement a custom Apex class that simulates a queue (First-In, First-Out) using two stacks (Last-In, First-Out). Your implementation should include enqueue and dequeue methods.

Methods to Implement

  • enqueue(Integer value): Adds an element to the back of the queue.
  • dequeue(): Removes and returns the element at the front of the queue.

Examples:

MyQueue q = new MyQueue();
q.enqueue(1);
q.enqueue(2);
System.assertEquals(1, q.dequeue()); // returns 1
q.enqueue(3);
System.assertEquals(2, q.dequeue()); // returns 2
System.assertEquals(3, q.dequeue()); // returns 3
Apex Code Editor

Welcome to Lightning Challenge!

Create an Account

Sign up to track your progress, earn points, and compete with others. Your solutions will be saved automatically.

Create account

How It Works

  • • Write your solution in the code editor
  • • Connect your Salesforce org to test
  • • Submit to check if your solution passes
  • • Use hints if you get stuck

Note

You can test your code by connecting to Salesforce, but to save your progress and earn points, you'll need to create an account. Your solutions and achievements will be tracked automatically once you're logged in.