{"id":18701969,"url":"https://github.com/recuencojones/stacksexercise","last_synced_at":"2025-11-09T00:30:40.888Z","repository":{"id":85224530,"uuid":"91554368","full_name":"RecuencoJones/StacksExercise","owner":"RecuencoJones","description":"Simple Queue based on two stacks exercise","archived":false,"fork":false,"pushed_at":"2017-05-18T07:35:47.000Z","size":3,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2024-12-28T05:41:59.961Z","etag":null,"topics":["exercise","fifo-queue","javascript"],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/RecuencoJones.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2017-05-17T08:48:34.000Z","updated_at":"2017-05-17T08:56:54.000Z","dependencies_parsed_at":"2023-05-03T04:17:15.085Z","dependency_job_id":null,"html_url":"https://github.com/RecuencoJones/StacksExercise","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RecuencoJones%2FStacksExercise","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RecuencoJones%2FStacksExercise/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RecuencoJones%2FStacksExercise/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RecuencoJones%2FStacksExercise/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/RecuencoJones","download_url":"https://codeload.github.com/RecuencoJones/StacksExercise/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":239565644,"owners_count":19660154,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["exercise","fifo-queue","javascript"],"created_at":"2024-11-07T11:43:08.110Z","updated_at":"2025-02-18T23:10:57.335Z","avatar_url":"https://github.com/RecuencoJones.png","language":"JavaScript","readme":"# Implement FIFO queue with two stacks\n\n## Requirements\n\n- node \\\u003e= 5\n- npm \\\u003e= 3\n\n## Install \u0026 Test\n\n```\nnpm run install\nnpm run test\n```\n\n- Check [stack.js](./stack.js) to understand how a Stack data structure works.\n- Edit your solution in [exercise.js](./exercise.js).\n- All tests in [test.js](./test.js) must pass. You can add further test cases.\n\n## Description\n\nA [queue](https://en.wikipedia.org/wiki/Queue_(abstract_data_type)) is an abstract data type that maintains the order in \nwhich elements were added to it, allowing the oldest elements to be removed from the front and new elements to be \nadded to the rear. This is called a First-In-First-Out (FIFO) data structure because the first element added to the \nqueue (i.e., the one that has been waiting the longest) is always the first one to be removed.\n\nA basic queue has the following operations:\n\n- **Enqueue**: add a new element to the end of the queue.\n- **Dequeue**: remove the element from the front of the queue and return it.\n\nIn this challenge, you must first implement a queue using two [stacks](https://en.wikipedia.org/wiki/Stack_(abstract_data_type)). \nThen process `n` queries, where each query is one of the following 3 types:\n\n1. `1 x`: Enqueue element `x` into the end of the queue.\n2. `2`: Dequeue the element at the front of the queue.\n3. `3`: Print the element at the front of the queue.\n\n## Input Format\n\nEach item `i` of the `n` list contains a single query in the form described in the problem statement above. \nAll three queries start with an integer denoting the query `type`, but only query `1` is followed by an additional \nspace-separated value, `x`, denoting the value to be enqueued.\n\n## Constraints\n\n- 1 \\\u003c= `n` \\\u003c= 10\u003csup\u003e5\u003c/sup\u003e \n- 1 \\\u003c= `type` \\\u003c= 3 \n- 1 \\\u003c= `|x|` \\\u003c= 10\u003csup\u003e9\u003c/sup\u003e \n- It is guaranteed that a valid answer always exists for each query of type `3`.\n\n## Output Format\n\nFor each query of type `3`, add the value of the element to the result vector and return it.\n\n## Sample Input\n\n```\n[\n  '1 42',\n  '2',\n  '1 14',\n  '3',\n  '1 28',\n  '3',\n  '1 60',\n  '1 78',\n  '2',\n  '2'\n]\n```\n\n## Sample Output\n\n```\n[\n  '14',\n  '14'\n]\n```\n\n## Explanation\n\nWe perform the following sequence of actions:\n\n- Enqueue 42; queue = { 42 }.\n- Dequeue the value at the head of the queue, 42; queue = { }.\n- Enqueue 14; queue = { }.\n- Append the value at the head of the queue to result vector; result = \\[ 14 \\], queue = { 14 }.\n- Enqueue 28; queue = { 14, 28 }.\n- Append the value at the head of the queue to result vector; result = \\[ 14, 14 \\], queue = { 14, 28 }.\n- Enqueue 60; queue = { 14, 28, 60 }.\n- Enqueue 78; queue = { 14, 28, 60, 78 }.\n- Dequeue the value at the head of the queue, 14; queue = { 28, 60, 78 }.\n- Dequeue the value at the head of the queue, 28; queue = { 60, 78 }.\n\n## Evaluation\n\n- Correct and optimized usage of [stacks](https://en.wikipedia.org/wiki/Stack_(abstract_data_type))\n- Cost of actions\n- Additional test cases\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frecuencojones%2Fstacksexercise","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frecuencojones%2Fstacksexercise","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frecuencojones%2Fstacksexercise/lists"}