{"id":34480,"date":"2024-11-01T09:28:27","date_gmt":"2024-11-01T09:28:27","guid":{"rendered":"http:\/\/atmokpo.com\/w\/?p=34480"},"modified":"2024-11-01T11:41:06","modified_gmt":"2024-11-01T11:41:06","slug":"javascript-coding-test-course-calculate-atm-withdrawal-time","status":"publish","type":"post","link":"https:\/\/atmokpo.com\/w\/34480\/","title":{"rendered":"JavaScript Coding Test Course, Calculate ATM Withdrawal Time"},"content":{"rendered":"<p><body><\/p>\n<p>Common problems that appear in programming interviews or coding tests are time calculation problems in various situations. In this post, we will discuss an algorithm problem that calculates the withdrawal time at an ATM. Assuming multiple users are using the ATM at the same time, we will write an algorithm to calculate the expected waiting time for each user.<\/p>\n<h2>Problem Description<\/h2>\n<p>Let\u2019s assume there is one ATM machine. There are several users waiting in line for this ATM. Each user can use the ATM at a specific time, and the time required to use the ATM can vary from person to person.<\/p>\n<p>The given input is an array of users&#8217; withdrawal times. The index of the array represents the user&#8217;s order, and the value stored at that index indicates the time taken by that user to use the ATM in seconds. For example, if an array of <code>[5, 3, 8]<\/code> is provided, the first user uses the ATM for 5 seconds, the second user for 3 seconds, and the third user for 8 seconds.<\/p>\n<h3>Input<\/h3>\n<pre>\n[5, 3, 8]\n<\/pre>\n<h3>Output<\/h3>\n<pre>\nArray of waiting times for each user: [0, 5, 8]\n<\/pre>\n<p>In the above example, the first user has a waiting time of 0 seconds, so they can use it immediately. The second user can use the ATM after the first user&#8217;s withdrawal is finished, so their waiting time is 5 seconds. The third user can use the ATM after the second user&#8217;s waiting time is over, making their waiting time 8 seconds.<\/p>\n<h2>Problem Solving Process<\/h2>\n<h3>Step 1: Understanding the Problem<\/h3>\n<p>To understand the problem, the following must be clarified:<\/p>\n<ul>\n<li>Each user using the ATM must wait until the previous user&#8217;s withdrawal is completed.<\/li>\n<li>To calculate waiting times, cumulative time must be tracked.<\/li>\n<li>The waiting times should be calculated in the order of withdrawal, and the result should be returned as an array.<\/li>\n<\/ul>\n<h3>Step 2: Designing the Algorithm<\/h3>\n<p>To solve this problem, the following algorithm can be used:<\/p>\n<ol>\n<li>Create an empty array to store each user&#8217;s waiting times.<\/li>\n<li>Initialize a variable <code>totalTime<\/code> to 0. This will be used to store cumulative waiting time.<\/li>\n<li>Loop through each user&#8217;s withdrawal time to calculate the waiting times:<\/li>\n<ul>\n<li>The current user&#8217;s waiting time is set to <code>totalTime<\/code>.<\/li>\n<li>Add the current user&#8217;s withdrawal time to <code>totalTime<\/code>.<\/li>\n<\/ul>\n<li>Return the waiting time array.<\/li>\n<\/ol>\n<h3>Step 3: Code Implementation<\/h3>\n<p>Now, let&#8217;s implement the algorithm in JavaScript code.<\/p>\n<pre>\nfunction calculateWaitTimes(atmTimes) {\n    let waitTimes = [];\n    let totalTime = 0;\n\n    for (let i = 0; i < atmTimes.length; i++) {\n        waitTimes[i] = totalTime; \/\/ Current user's waiting time\n        totalTime += atmTimes[i]; \/\/ Update cumulative time\n    }\n\n    return waitTimes;\n}\n\n\/\/ Example execution\nconst inputTimes = [5, 3, 8];\nconst outputWaitTimes = calculateWaitTimes(inputTimes);\nconsole.log(outputWaitTimes); \/\/ [0, 5, 8]\n<\/pre>\n<h2>Testing and Validation<\/h2>\n<p>After implementing the function, let\u2019s validate it using various test cases to ensure it produces the correct results.<\/p>\n<pre>\nconsole.log(calculateWaitTimes([0, 0, 0]));       \/\/ [0, 0, 0]\nconsole.log(calculateWaitTimes([1, 2, 3]));       \/\/ [0, 1, 3]\nconsole.log(calculateWaitTimes([10, 20, 30]));    \/\/ [0, 10, 30]\nconsole.log(calculateWaitTimes([5]));              \/\/ [0]\nconsole.log(calculateWaitTimes([]));               \/\/ []\n<\/pre>\n<h2>Complexity Analysis<\/h2>\n<p>The time complexity of this algorithm is O(n). It increases in proportion to the number of users since it traverses the array once. The space complexity is also O(n), as an array is needed to store the waiting times.<\/p>\n<h2>Conclusion<\/h2>\n<p>In this post, we examined the problem of calculating withdrawal times at an ATM. This problem can serve as a useful exercise for mastering the basics of algorithm design and time calculation. Through the implementation process in JavaScript, I hope you have learned a more accessible approach to similar problems encountered in actual coding tests. It is hoped that this problem helps you understand the fundamental approaches to algorithms and time complexity and enhances your problem-solving skills.<\/p>\n<p><\/body><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Common problems that appear in programming interviews or coding tests are time calculation problems in various situations. In this post, we will discuss an algorithm problem that calculates the withdrawal time at an ATM. Assuming multiple users are using the ATM at the same time, we will write an algorithm to calculate the expected waiting &hellip; <a href=\"https:\/\/atmokpo.com\/w\/34480\/\" class=\"more-link\">\ub354 \ubcf4\uae30<span class=\"screen-reader-text\"> &#8220;JavaScript Coding Test Course, Calculate ATM Withdrawal Time&#8221;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[141],"tags":[],"class_list":["post-34480","post","type-post","status-publish","format-standard","hentry","category-javascript-coding-test"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v26.2 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>JavaScript Coding Test Course, Calculate ATM Withdrawal Time - \ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/atmokpo.com\/w\/34480\/\" \/>\n<meta property=\"og:locale\" content=\"ko_KR\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"JavaScript Coding Test Course, Calculate ATM Withdrawal Time - \ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8\" \/>\n<meta property=\"og:description\" content=\"Common problems that appear in programming interviews or coding tests are time calculation problems in various situations. In this post, we will discuss an algorithm problem that calculates the withdrawal time at an ATM. Assuming multiple users are using the ATM at the same time, we will write an algorithm to calculate the expected waiting &hellip; \ub354 \ubcf4\uae30 &quot;JavaScript Coding Test Course, Calculate ATM Withdrawal Time&quot;\" \/>\n<meta property=\"og:url\" content=\"https:\/\/atmokpo.com\/w\/34480\/\" \/>\n<meta property=\"og:site_name\" content=\"\ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8\" \/>\n<meta property=\"article:published_time\" content=\"2024-11-01T09:28:27+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2024-11-01T11:41:06+00:00\" \/>\n<meta name=\"author\" content=\"root\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@bebubo4\" \/>\n<meta name=\"twitter:site\" content=\"@bebubo4\" \/>\n<meta name=\"twitter:label1\" content=\"\uae00\uc4f4\uc774\" \/>\n\t<meta name=\"twitter:data1\" content=\"root\" \/>\n\t<meta name=\"twitter:label2\" content=\"\uc608\uc0c1 \ub418\ub294 \ud310\ub3c5 \uc2dc\uac04\" \/>\n\t<meta name=\"twitter:data2\" content=\"3\ubd84\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/atmokpo.com\/w\/34480\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/atmokpo.com\/w\/34480\/\"},\"author\":{\"name\":\"root\",\"@id\":\"https:\/\/atmokpo.com\/w\/#\/schema\/person\/91b6b3b138fbba0efb4ae64b1abd81d7\"},\"headline\":\"JavaScript Coding Test Course, Calculate ATM Withdrawal Time\",\"datePublished\":\"2024-11-01T09:28:27+00:00\",\"dateModified\":\"2024-11-01T11:41:06+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/atmokpo.com\/w\/34480\/\"},\"wordCount\":528,\"publisher\":{\"@id\":\"https:\/\/atmokpo.com\/w\/#organization\"},\"articleSection\":[\"Javascript Coding Test\"],\"inLanguage\":\"ko-KR\"},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/atmokpo.com\/w\/34480\/\",\"url\":\"https:\/\/atmokpo.com\/w\/34480\/\",\"name\":\"JavaScript Coding Test Course, Calculate ATM Withdrawal Time - \ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8\",\"isPartOf\":{\"@id\":\"https:\/\/atmokpo.com\/w\/#website\"},\"datePublished\":\"2024-11-01T09:28:27+00:00\",\"dateModified\":\"2024-11-01T11:41:06+00:00\",\"breadcrumb\":{\"@id\":\"https:\/\/atmokpo.com\/w\/34480\/#breadcrumb\"},\"inLanguage\":\"ko-KR\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/atmokpo.com\/w\/34480\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/atmokpo.com\/w\/34480\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"\ud648\",\"item\":\"https:\/\/atmokpo.com\/w\/en\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"JavaScript Coding Test Course, Calculate ATM Withdrawal Time\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/atmokpo.com\/w\/#website\",\"url\":\"https:\/\/atmokpo.com\/w\/\",\"name\":\"\ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8\",\"description\":\"\",\"publisher\":{\"@id\":\"https:\/\/atmokpo.com\/w\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/atmokpo.com\/w\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"ko-KR\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/atmokpo.com\/w\/#organization\",\"name\":\"\ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8\",\"url\":\"https:\/\/atmokpo.com\/w\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"ko-KR\",\"@id\":\"https:\/\/atmokpo.com\/w\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/atmokpo.com\/w\/wp-content\/uploads\/2024\/11\/logo.png\",\"contentUrl\":\"https:\/\/atmokpo.com\/w\/wp-content\/uploads\/2024\/11\/logo.png\",\"width\":400,\"height\":400,\"caption\":\"\ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8\"},\"image\":{\"@id\":\"https:\/\/atmokpo.com\/w\/#\/schema\/logo\/image\/\"},\"sameAs\":[\"https:\/\/x.com\/bebubo4\"]},{\"@type\":\"Person\",\"@id\":\"https:\/\/atmokpo.com\/w\/#\/schema\/person\/91b6b3b138fbba0efb4ae64b1abd81d7\",\"name\":\"root\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"ko-KR\",\"@id\":\"https:\/\/atmokpo.com\/w\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/708197b41fc6435a7ce22d951b25d4a47e9e904270cb1f04682d4f025066f80c?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/708197b41fc6435a7ce22d951b25d4a47e9e904270cb1f04682d4f025066f80c?s=96&d=mm&r=g\",\"caption\":\"root\"},\"sameAs\":[\"http:\/\/atmokpo.com\/w\"],\"url\":\"https:\/\/atmokpo.com\/w\/author\/root\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"JavaScript Coding Test Course, Calculate ATM Withdrawal Time - \ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/atmokpo.com\/w\/34480\/","og_locale":"ko_KR","og_type":"article","og_title":"JavaScript Coding Test Course, Calculate ATM Withdrawal Time - \ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8","og_description":"Common problems that appear in programming interviews or coding tests are time calculation problems in various situations. In this post, we will discuss an algorithm problem that calculates the withdrawal time at an ATM. Assuming multiple users are using the ATM at the same time, we will write an algorithm to calculate the expected waiting &hellip; \ub354 \ubcf4\uae30 \"JavaScript Coding Test Course, Calculate ATM Withdrawal Time\"","og_url":"https:\/\/atmokpo.com\/w\/34480\/","og_site_name":"\ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8","article_published_time":"2024-11-01T09:28:27+00:00","article_modified_time":"2024-11-01T11:41:06+00:00","author":"root","twitter_card":"summary_large_image","twitter_creator":"@bebubo4","twitter_site":"@bebubo4","twitter_misc":{"\uae00\uc4f4\uc774":"root","\uc608\uc0c1 \ub418\ub294 \ud310\ub3c5 \uc2dc\uac04":"3\ubd84"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/atmokpo.com\/w\/34480\/#article","isPartOf":{"@id":"https:\/\/atmokpo.com\/w\/34480\/"},"author":{"name":"root","@id":"https:\/\/atmokpo.com\/w\/#\/schema\/person\/91b6b3b138fbba0efb4ae64b1abd81d7"},"headline":"JavaScript Coding Test Course, Calculate ATM Withdrawal Time","datePublished":"2024-11-01T09:28:27+00:00","dateModified":"2024-11-01T11:41:06+00:00","mainEntityOfPage":{"@id":"https:\/\/atmokpo.com\/w\/34480\/"},"wordCount":528,"publisher":{"@id":"https:\/\/atmokpo.com\/w\/#organization"},"articleSection":["Javascript Coding Test"],"inLanguage":"ko-KR"},{"@type":"WebPage","@id":"https:\/\/atmokpo.com\/w\/34480\/","url":"https:\/\/atmokpo.com\/w\/34480\/","name":"JavaScript Coding Test Course, Calculate ATM Withdrawal Time - \ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8","isPartOf":{"@id":"https:\/\/atmokpo.com\/w\/#website"},"datePublished":"2024-11-01T09:28:27+00:00","dateModified":"2024-11-01T11:41:06+00:00","breadcrumb":{"@id":"https:\/\/atmokpo.com\/w\/34480\/#breadcrumb"},"inLanguage":"ko-KR","potentialAction":[{"@type":"ReadAction","target":["https:\/\/atmokpo.com\/w\/34480\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/atmokpo.com\/w\/34480\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"\ud648","item":"https:\/\/atmokpo.com\/w\/en\/"},{"@type":"ListItem","position":2,"name":"JavaScript Coding Test Course, Calculate ATM Withdrawal Time"}]},{"@type":"WebSite","@id":"https:\/\/atmokpo.com\/w\/#website","url":"https:\/\/atmokpo.com\/w\/","name":"\ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8","description":"","publisher":{"@id":"https:\/\/atmokpo.com\/w\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/atmokpo.com\/w\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"ko-KR"},{"@type":"Organization","@id":"https:\/\/atmokpo.com\/w\/#organization","name":"\ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8","url":"https:\/\/atmokpo.com\/w\/","logo":{"@type":"ImageObject","inLanguage":"ko-KR","@id":"https:\/\/atmokpo.com\/w\/#\/schema\/logo\/image\/","url":"https:\/\/atmokpo.com\/w\/wp-content\/uploads\/2024\/11\/logo.png","contentUrl":"https:\/\/atmokpo.com\/w\/wp-content\/uploads\/2024\/11\/logo.png","width":400,"height":400,"caption":"\ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8"},"image":{"@id":"https:\/\/atmokpo.com\/w\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/x.com\/bebubo4"]},{"@type":"Person","@id":"https:\/\/atmokpo.com\/w\/#\/schema\/person\/91b6b3b138fbba0efb4ae64b1abd81d7","name":"root","image":{"@type":"ImageObject","inLanguage":"ko-KR","@id":"https:\/\/atmokpo.com\/w\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/708197b41fc6435a7ce22d951b25d4a47e9e904270cb1f04682d4f025066f80c?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/708197b41fc6435a7ce22d951b25d4a47e9e904270cb1f04682d4f025066f80c?s=96&d=mm&r=g","caption":"root"},"sameAs":["http:\/\/atmokpo.com\/w"],"url":"https:\/\/atmokpo.com\/w\/author\/root\/"}]}},"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack-related-posts":[],"_links":{"self":[{"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/posts\/34480","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/comments?post=34480"}],"version-history":[{"count":1,"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/posts\/34480\/revisions"}],"predecessor-version":[{"id":34481,"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/posts\/34480\/revisions\/34481"}],"wp:attachment":[{"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/media?parent=34480"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/categories?post=34480"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/tags?post=34480"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}