{"id":34500,"date":"2024-11-01T09:28:41","date_gmt":"2024-11-01T09:28:41","guid":{"rendered":"http:\/\/atmokpo.com\/w\/?p=34500"},"modified":"2024-11-01T11:41:01","modified_gmt":"2024-11-01T11:41:01","slug":"javascript-coding-test-course-i-dont-want-to-be-a-liar","status":"publish","type":"post","link":"https:\/\/atmokpo.com\/w\/34500\/","title":{"rendered":"JavaScript Coding Test Course, I Don&#8217;t Want to Be a Liar"},"content":{"rendered":"<p><body><\/p>\n<p>Coding tests are a challenging process that many developers face. Especially when solving problems in JavaScript, one must have a good understanding of the language&#8217;s characteristics. In this course, we will explore the characteristics of JavaScript and algorithmic approaches through a problem titled &#8216;I Don&#8217;t Want to be a Liar.&#8217;<\/p>\n<h2>Problem Description<\/h2>\n<p>Imagine the following situation. You are going camping with several friends. Some of your friends are quirky and have decided to lie about a certain incident. Here is what each friend has claimed.<\/p>\n<p>The given input is represented as an array, where each array value is the number of friends that a friend claims. Your goal is to determine that if the number of friends stated in the claims is a majority, then those friends are considered to be lying.<\/p>\n<h3>Example Input<\/h3>\n<pre>\n    const statements = [\n        [0, 1], \/\/ Friend 0 claims friend 1\n        [1, 2], \/\/ Friend 1 claims friend 2\n        [2, 0], \/\/ Friend 2 claims friend 0\n        [3, 2], \/\/ Friend 3 claims friend 2 (here, friend 3 is a liar)\n    ];\n    <\/pre>\n<h3>Example Output<\/h3>\n<p>Number of lying friends: 1<\/p>\n<h2>Problem Solving Process<\/h2>\n<p>The first step in approaching this problem is to understand the relationships in which each friend claims someone. We can use a directed graph to represent each friend as a node and the claiming relationship as edges.<\/p>\n<h3>1. Data Structure Design<\/h3>\n<p>First, we need to define a data structure that can store the claims made by each friend. To do this, we can use an object to map each friend&#8217;s ID to a list of IDs of the friends they claim.<\/p>\n<pre>\n    const graph = {};\n    statements.forEach(([speaker, listener]) =&gt; {\n        if (!graph[speaker]) {\n            graph[speaker] = [];\n        }\n        graph[speaker].push(listener);\n    });\n    <\/pre>\n<h3>2. Exploration through DFS\/BFS<\/h3>\n<p>To explore the relationships between claims, we can use either DFS (Depth-First Search) or BFS (Breadth-First Search). This will allow us to verify the validity of each friend&#8217;s claims.<\/p>\n<pre>\n    function hasContradictions(speaker) {\n        const visited = new Set();\n        const stack = [speaker];\n\n        while (stack.length) {\n            const curr = stack.pop();\n            if (visited.has(curr)) {\n                return true; \/\/ A contradiction occurs when visiting a node that has already been visited\n            }\n            visited.add(curr);\n\n            if (graph[curr]) {\n                graph[curr].forEach(listener =&gt; {\n                    stack.push(listener);\n                });\n            }\n        }\n        return false;\n    }\n    <\/pre>\n<h3>3. Check all friends<\/h3>\n<p>We count the number of friends who have invalid claims by checking all friends. This is the process of identifying how many among the total friends are creating contradictions.<\/p>\n<pre>\n    let liarsCount = 0;\n    for (let i = 0; i &lt; statements.length; i++) {\n        if (hasContradictions(i)) {\n            liarsCount++;\n        }\n    }\n    return liarsCount;\n    <\/pre>\n<h2>Final Code<\/h2>\n<pre>\n    function findLiars(statements) {\n        const graph = {};\n        statements.forEach(([speaker, listener]) =&gt; {\n            if (!graph[speaker]) {\n                graph[speaker] = [];\n            }\n            graph[speaker].push(listener);\n        });\n\n        function hasContradictions(speaker) {\n            const visited = new Set();\n            const stack = [speaker];\n\n            while (stack.length) {\n                const curr = stack.pop();\n                if (visited.has(curr)) {\n                    return true; \n                }\n                visited.add(curr);\n\n                if (graph[curr]) {\n                    graph[curr].forEach(listener =&gt; {\n                        stack.push(listener);\n                    });\n                }\n            }\n            return false;\n        }\n\n        let liarsCount = 0;\n        for (let i = 0; i &lt; statements.length; i++) {\n            if (hasContradictions(i)) {\n                liarsCount++;\n            }\n        }\n        return liarsCount;\n    }\n\n    console.log(findLiars(statements)); \/\/ Output: 1\n    <\/pre>\n<h2>Conclusion<\/h2>\n<p>Through problems like the one described above, we learned how to apply basic syntax in JavaScript, utilize data structures, and implement DFS\/BFS algorithms. It is important to practice such problems while preparing for coding tests to enhance algorithmic thinking.<\/p>\n<p><\/body><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Coding tests are a challenging process that many developers face. Especially when solving problems in JavaScript, one must have a good understanding of the language&#8217;s characteristics. In this course, we will explore the characteristics of JavaScript and algorithmic approaches through a problem titled &#8216;I Don&#8217;t Want to be a Liar.&#8217; Problem Description Imagine the following &hellip; <a href=\"https:\/\/atmokpo.com\/w\/34500\/\" class=\"more-link\">\ub354 \ubcf4\uae30<span class=\"screen-reader-text\"> &#8220;JavaScript Coding Test Course, I Don&#8217;t Want to Be a Liar&#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-34500","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, I Don&#039;t Want to Be a Liar - \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\/34500\/\" \/>\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, I Don&#039;t Want to Be a Liar - \ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8\" \/>\n<meta property=\"og:description\" content=\"Coding tests are a challenging process that many developers face. Especially when solving problems in JavaScript, one must have a good understanding of the language&#8217;s characteristics. In this course, we will explore the characteristics of JavaScript and algorithmic approaches through a problem titled &#8216;I Don&#8217;t Want to be a Liar.&#8217; Problem Description Imagine the following &hellip; \ub354 \ubcf4\uae30 &quot;JavaScript Coding Test Course, I Don&#8217;t Want to Be a Liar&quot;\" \/>\n<meta property=\"og:url\" content=\"https:\/\/atmokpo.com\/w\/34500\/\" \/>\n<meta property=\"og:site_name\" content=\"\ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8\" \/>\n<meta property=\"article:published_time\" content=\"2024-11-01T09:28:41+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2024-11-01T11:41:01+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\/34500\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/atmokpo.com\/w\/34500\/\"},\"author\":{\"name\":\"root\",\"@id\":\"https:\/\/atmokpo.com\/w\/#\/schema\/person\/91b6b3b138fbba0efb4ae64b1abd81d7\"},\"headline\":\"JavaScript Coding Test Course, I Don&#8217;t Want to Be a Liar\",\"datePublished\":\"2024-11-01T09:28:41+00:00\",\"dateModified\":\"2024-11-01T11:41:01+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/atmokpo.com\/w\/34500\/\"},\"wordCount\":347,\"publisher\":{\"@id\":\"https:\/\/atmokpo.com\/w\/#organization\"},\"articleSection\":[\"Javascript Coding Test\"],\"inLanguage\":\"ko-KR\"},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/atmokpo.com\/w\/34500\/\",\"url\":\"https:\/\/atmokpo.com\/w\/34500\/\",\"name\":\"JavaScript Coding Test Course, I Don't Want to Be a Liar - \ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8\",\"isPartOf\":{\"@id\":\"https:\/\/atmokpo.com\/w\/#website\"},\"datePublished\":\"2024-11-01T09:28:41+00:00\",\"dateModified\":\"2024-11-01T11:41:01+00:00\",\"breadcrumb\":{\"@id\":\"https:\/\/atmokpo.com\/w\/34500\/#breadcrumb\"},\"inLanguage\":\"ko-KR\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/atmokpo.com\/w\/34500\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/atmokpo.com\/w\/34500\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"\ud648\",\"item\":\"https:\/\/atmokpo.com\/w\/en\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"JavaScript Coding Test Course, I Don&#8217;t Want to Be a Liar\"}]},{\"@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, I Don't Want to Be a Liar - \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\/34500\/","og_locale":"ko_KR","og_type":"article","og_title":"JavaScript Coding Test Course, I Don't Want to Be a Liar - \ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8","og_description":"Coding tests are a challenging process that many developers face. Especially when solving problems in JavaScript, one must have a good understanding of the language&#8217;s characteristics. In this course, we will explore the characteristics of JavaScript and algorithmic approaches through a problem titled &#8216;I Don&#8217;t Want to be a Liar.&#8217; Problem Description Imagine the following &hellip; \ub354 \ubcf4\uae30 \"JavaScript Coding Test Course, I Don&#8217;t Want to Be a Liar\"","og_url":"https:\/\/atmokpo.com\/w\/34500\/","og_site_name":"\ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8","article_published_time":"2024-11-01T09:28:41+00:00","article_modified_time":"2024-11-01T11:41:01+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\/34500\/#article","isPartOf":{"@id":"https:\/\/atmokpo.com\/w\/34500\/"},"author":{"name":"root","@id":"https:\/\/atmokpo.com\/w\/#\/schema\/person\/91b6b3b138fbba0efb4ae64b1abd81d7"},"headline":"JavaScript Coding Test Course, I Don&#8217;t Want to Be a Liar","datePublished":"2024-11-01T09:28:41+00:00","dateModified":"2024-11-01T11:41:01+00:00","mainEntityOfPage":{"@id":"https:\/\/atmokpo.com\/w\/34500\/"},"wordCount":347,"publisher":{"@id":"https:\/\/atmokpo.com\/w\/#organization"},"articleSection":["Javascript Coding Test"],"inLanguage":"ko-KR"},{"@type":"WebPage","@id":"https:\/\/atmokpo.com\/w\/34500\/","url":"https:\/\/atmokpo.com\/w\/34500\/","name":"JavaScript Coding Test Course, I Don't Want to Be a Liar - \ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8","isPartOf":{"@id":"https:\/\/atmokpo.com\/w\/#website"},"datePublished":"2024-11-01T09:28:41+00:00","dateModified":"2024-11-01T11:41:01+00:00","breadcrumb":{"@id":"https:\/\/atmokpo.com\/w\/34500\/#breadcrumb"},"inLanguage":"ko-KR","potentialAction":[{"@type":"ReadAction","target":["https:\/\/atmokpo.com\/w\/34500\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/atmokpo.com\/w\/34500\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"\ud648","item":"https:\/\/atmokpo.com\/w\/en\/"},{"@type":"ListItem","position":2,"name":"JavaScript Coding Test Course, I Don&#8217;t Want to Be a Liar"}]},{"@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\/34500","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=34500"}],"version-history":[{"count":1,"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/posts\/34500\/revisions"}],"predecessor-version":[{"id":34501,"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/posts\/34500\/revisions\/34501"}],"wp:attachment":[{"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/media?parent=34500"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/categories?post=34500"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/tags?post=34500"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}