# MyCodeSolution > MyCodeSolution (mycodesolution.com) helps developers practise technical coding tests. It publishes free, step-by-step explained solutions to 39 CodinGame puzzles (each in English and French) (problem, approach, complexity, commented C/Java/Python code, common mistakes, FAQ) and makes Coding Solutions, a Google Chrome extension that reads a coding exercise or technical multiple-choice question on screen and explains the solution (CodinGame, HackerRank, LeetCode, Codility; 29 programming languages; rated 5.0/5 by 16 reviewers and used by 928 people on the Chrome Web Store). Site in English, French and Spanish. ## Chrome extensions - [Coding Solutions](https://chromewebstore.google.com/detail/coding-solutions/bnodpobghabokpfdogogbnpkojphmfmo): practice extension for coding tests and technical MCQs; explains the solution step by step so you understand the approach. Token packs from 19.99 EUR. - [Coding Solutions Invisible Version](https://chromewebstore.google.com/detail/mfcimmihiejnokepdimeajkgldkldgak): same engine, account and credits as Coding Solutions, with a minimalist interface. - [InterviewRecord](https://chromewebstore.google.com/detail/efomkhkghiijpnmgglpekjajjjnikekf): live video-interview assistant for Google Meet, Microsoft Teams and Zoom (live transcription, AI-suggested answers, notes). Website: https://solution-entretien.com ## Main pages - [Home (FR)](https://mycodesolution.com/) · [Home (EN)](https://mycodesolution.com/en/) · [Home (ES)](https://mycodesolution.com/es/) - [All CodinGame solutions, by difficulty](https://mycodesolution.com/solution/) - [Solutions CodinGame en français](https://mycodesolution.com/fr/solution/) ## Coding-test preparation guides (one per platform) - [All guides](https://mycodesolution.com/guide/) · [FR](https://mycodesolution.com/fr/guide/) - [CodinGame test guide](https://mycodesolution.com/guide/codingame/) · [FR](https://mycodesolution.com/fr/guide/codingame/): What a CodinGame recruitment test looks like, the question types, a 7-day preparation plan and 39 explained puzzles to practise on. - [HackerRank test guide](https://mycodesolution.com/guide/hackerrank/) · [FR](https://mycodesolution.com/fr/guide/hackerrank/): How a HackerRank hiring test works: duration, scoring, problem families, common failure causes and a two-week training plan. - [Codility test guide](https://mycodesolution.com/guide/codility/) · [FR](https://mycodesolution.com/fr/guide/codility/): Everything about the Codility hiring test: the correctness + performance score, the lessons to master, the traps and how to train. - [SkillValue test guide](https://mycodesolution.com/guide/skillvalue/) · [FR](https://mycodesolution.com/fr/guide/skillvalue/): The SkillValue hiring test explained: technology-specific MCQs, scoring, duration, typical questions and a revision method. - [Coderbyte test guide](https://mycodesolution.com/guide/coderbyte/) · [FR](https://mycodesolution.com/fr/guide/coderbyte/): How a Coderbyte hiring test works: coding challenges, open questions, scoring, traps and a training plan. ## Technical MCQs with answers (one page per language, 12 explained questions each) - [All MCQs](https://mycodesolution.com/qcm/) · [FR](https://mycodesolution.com/fr/qcm/) - [Java interview MCQs](https://mycodesolution.com/qcm/java/) · [FR](https://mycodesolution.com/fr/qcm/java/): String pool and equals, collections, exceptions, Integer cache, streams, static vs override. - [Python interview MCQs](https://mycodesolution.com/qcm/python/) · [FR](https://mycodesolution.com/fr/qcm/python/): mutable defaults, is vs ==, slicing, shallow vs deep copy, closures, generators, decorators. - [JavaScript interview MCQs](https://mycodesolution.com/qcm/javascript/) · [FR](https://mycodesolution.com/fr/qcm/javascript/): hoisting, closures, this, coercion, event loop, array methods, NaN. - [SQL interview MCQs](https://mycodesolution.com/qcm/sql/) · [FR](https://mycodesolution.com/fr/qcm/sql/): joins, GROUP BY/HAVING, NULL semantics, NOT IN vs NOT EXISTS, window functions, indexes. - [C# interview MCQs](https://mycodesolution.com/qcm/csharp/) · [FR](https://mycodesolution.com/fr/qcm/csharp/): value vs reference types, string comparison, LINQ deferred execution, async, init, boxing. ## Platform comparison and author - [CodinGame vs HackerRank vs Codility (candidate comparison, with table)](https://mycodesolution.com/compare/codingame-vs-hackerrank-vs-codility/) · [FR](https://mycodesolution.com/fr/comparatif/codingame-hackerrank-codility/) - [About the author, Louis](https://mycodesolution.com/about/) · [FR](https://mycodesolution.com/a-propos/): independent developer, builds the three extensions and writes every solution, guide and MCQ on the site. ## CodinGame solutions (explained) ### Easy - [ASCII Art](https://mycodesolution.com/solution/ascii-art/index.html) · [FR](https://mycodesolution.com/fr/solution/ascii-art/index.html): Convert each character of the text to an index: 0-25 for letters (case-insensitive) and 26 for anything else, which is drawn as "?". Then, for each of the H rows of the font, print the slice row[index*L : index*L + L] for every character, and end the row with a newline. The output is built row by row, not letter by letter. - [Chuck Norris](https://mycodesolution.com/solution/chuck-norris/index.html) · [FR](https://mycodesolution.com/fr/solution/chuck-norris/index.html): Convert every character to its 7-bit ASCII code, concatenate all the bits into one string, then split that string into runs of identical bits. Each run becomes two blocks: "0" for a run of 1s or "00" for a run of 0s, followed by as many zeros as the run length, all separated by spaces. Concatenating before encoding is essential because a run can continue from one character into the next. - [Defibrillators](https://mycodesolution.com/solution/defibrillators/index.html) · [FR](https://mycodesolution.com/fr/solution/defibrillators/index.html): Parse the user's longitude and latitude (replacing the decimal comma with a dot), then for each defibrillator split the line on ';', read fields 4 and 5 as longitude and latitude, convert everything to radians and compute the equirectangular distance x = dLon * cos((latA + latB) / 2), y = dLat, d = sqrt(x^2 + y^2). Keep the name (field 1) of the smallest distance and print it. - [Horse-racing Duals](https://mycodesolution.com/solution/horse-racing-duals/index.html) · [FR](https://mycodesolution.com/fr/solution/horse-racing-duals/index.html): Read all N strengths into an array, sort it, and scan it once comparing each value with the next one: the smallest of those adjacent differences is the answer. Sorting guarantees that the closest pair are neighbours, so the O(N^2) comparison of every pair is unnecessary and the solution runs in O(N log N), fast enough for 100,000 horses. - [Mars Lander - Episode 1](https://mycodesolution.com/solution/mars-lander-1/index.html) · [FR](https://mycodesolution.com/fr/solution/mars-lander-1/index.html): Keep the lander vertical (rotation 0) and decide each turn between thrust 0 and thrust 4. The robust way is to simulate: if you wait one more turn and then ramp the thrust up to 4 (it can only rise by 1 per turn), will the vertical speed still be above -40 m/s when you reach the ground? If yes, keep free-falling; if not, output thrust 4. A simpler rule, full thrust whenever the vertical speed drops below about -37 m/s, also passes all tests. - [MIME Type](https://mycodesolution.com/solution/mime-type/index.html) · [FR](https://mycodesolution.com/fr/solution/mime-type/index.html): Load the extension-to-MIME table into a hash map keyed by the lowercased extension, then for each file name take the substring after the last dot, lowercase it and look it up. If the name has no dot, or the extension is not in the table, print UNKNOWN. Everything is O(1) per lookup, so the whole puzzle runs in linear time in the size of the input. - [Onboarding](https://mycodesolution.com/solution/onboarding/index.html) · [FR](https://mycodesolution.com/fr/solution/onboarding/index.html): Each turn, read the two enemy names and their distances, then print the name of the enemy with the smaller distance. Repeat forever inside the game loop; the referee ends the program when the game is over. Converting the distances to integers before comparing them is the only real trap. - [Power of Thor - Episode 1](https://mycodesolution.com/solution/power-of-thor/index.html) · [FR](https://mycodesolution.com/fr/solution/power-of-thor/index.html): Compare Thor's coordinates with the light's: add N or S if the Y values differ, then E or W if the X values differ, print the combined direction, and update Thor's position yourself because the game never sends it again. Moving diagonally while both axes differ is the shortest path, so you always arrive within the allowed number of turns. - [Skynet: The Chasm](https://mycodesolution.com/solution/skynet-the-chasm/index.html) · [FR](https://mycodesolution.com/fr/solution/skynet-the-chasm/index.html): The minimum speed that clears a gap of G cells is G + 1, and keeping exactly that speed makes stopping on the landing platform easy. Each turn: SLOW if you are past the gap or faster than G + 1, SPEED if you are slower than G + 1, JUMP when a jump from your current cell lands beyond the gap (x + speed >= road + gap), and WAIT otherwise. - [Temperatures](https://mycodesolution.com/solution/temperatures/index.html) · [FR](https://mycodesolution.com/fr/solution/temperatures/index.html): Read every temperature once and keep the one with the smallest absolute value; when two readings are equally close to zero (like -5 and 5), keep the positive one. If the list is empty (N = 0), print 0. This single linear pass runs in O(n) time and O(1) memory. - [The Descent](https://mycodesolution.com/solution/the-descent/index.html) · [FR](https://mycodesolution.com/fr/solution/the-descent/index.html): Each turn, read the eight mountain heights, find the index of the tallest one and print that index; the ship fires on it. Shooting the highest mountain every turn is enough, because only the tallest peak can reach the ship first. It is a linear search for the maximum (argmax) inside the game loop. ### Medium - [Bender - Episode 1](https://mycodesolution.com/solution/bender/index.html) · [FR](https://mycodesolution.com/fr/solution/bender/index.html): Simulate Bender one move at a time: keep his position, direction, breaker mode and inverted priorities, and when the tile ahead is blocked try SOUTH, EAST, NORTH, WEST (or the reverse) in order. To print LOOP reliably, record every (x, y, direction, breaker, inverted) state you have been in and stop when one repeats, clearing that record each time a breakable wall is destroyed because the map has changed. - [Conway Sequence](https://mycodesolution.com/solution/conway-sequence/index.html) · [FR](https://mycodesolution.com/fr/solution/conway-sequence/index.html): Start from the list [R] and apply the look-and-say step L-1 times: walk the current list, group equal consecutive values and replace each group by its length followed by the value. Work on a list of integers rather than on a string of digits, because R can be 2 or 3 digits long and must be read as one element. Print the final list separated by single spaces. - [Death First Search - Episode 1](https://mycodesolution.com/solution/skynet-the-virus/index.html) · [FR](https://mycodesolution.com/fr/solution/skynet-the-virus/index.html): Each turn, run a breadth-first search from the Skynet agent to find the closest gateway, then cut the first link of that shortest path. If the agent is next to a gateway, this cuts exactly that link; otherwise it removes a link on the agent's best route. In Episode 1 each node touches at most one gateway, so this greedy rule never loses. - [Dwarfs standing on the shoulders of giants](https://mycodesolution.com/solution/dwarfs-on-giants/index.html) · [FR](https://mycodesolution.com/fr/solution/dwarfs-on-giants/index.html): Build a directed graph where an edge x → y means x influenced y, then compute the longest path in this acyclic graph. With memoized DFS, the chain length starting at a person is 1 plus the longest chain among the people they influenced (1 if they influenced nobody), and the answer is the maximum over all people. Count people, not edges. - [Indiana - Episode 1](https://mycodesolution.com/solution/indiana1/index.html) · [FR](https://mycodesolution.com/fr/solution/indiana1/index.html): Read the grid of room types once, then each turn look up where Indy leaves the current room given its type and the side he entered from (TOP, LEFT or RIGHT). Exits are always DOWN, LEFT or RIGHT, so the next room is (x, y+1), (x-1, y) or (x+1, y), and you print those coordinates. A small table from (type, entry) to exit replaces any pathfinding. - [Mars Lander - Episode 2](https://mycodesolution.com/solution/mars-lander-2/index.html) · [FR](https://mycodesolution.com/fr/solution/mars-lander-2/index.html): Find the flat landing segment, then each turn pick a behaviour based on the lander's situation: if it is not above the zone, brake when it moves too fast or the wrong way and otherwise tilt about 21° toward the zone at full power to accelerate without losing altitude; once above the zone, kill the horizontal speed by pointing the thrust against the velocity vector, and straighten to 0° for the final descent. The angle that cancels a velocity is asin(hSpeed / speed) in degrees. - [Mayan Calculation](https://mycodesolution.com/solution/mayan-calculation/index.html) · [FR](https://mycodesolution.com/fr/solution/mayan-calculation/index.html): Treat every Mayan digit as a block of H text rows and turn it into a single string key, so the 20 reference glyphs become a lookup table from key to value 0-19. Read each operand top to bottom as base-20 digits (most significant first) into a 64-bit integer with value = value*20 + digit, apply the operator, then repeatedly take result % 20 to print the answer back as glyphs, printing the zero glyph when the result is 0. - [Network Cabling](https://mycodesolution.com/solution/network-cabling/index.html) · [FR](https://mycodesolution.com/fr/solution/network-cabling/index.html): The horizontal cable must run from the smallest to the largest x, so its length is fixed at xMax - xMin; the only choice is its height. The sum of vertical drops |y_i - Y| is minimised when Y is a median of the building y-coordinates, so sort the y values, take ys[N/2], and add every |y_i - median| to xMax - xMin using 64-bit integers. - [Scrabble](https://mycodesolution.com/solution/scrabble/index.html) · [FR](https://mycodesolution.com/fr/solution/scrabble/index.html): Count how many times each letter appears in your 7 tiles, then scan the dictionary once: a word is playable if, for every letter, it uses no more copies than you have. Score playable words with the Scrabble letter values and keep the best one with a strict greater-than comparison, so that on a tie the word that appears first in the dictionary wins. - [Shadows of the Knight - Episode 1](https://mycodesolution.com/solution/heat-detector/index.html) · [FR](https://mycodesolution.com/fr/solution/heat-detector/index.html): Maintain the rectangle of cells where the bomb can still be, starting with the whole building. Each turn, use the direction you receive to shrink it (U sets the bottom bound to y - 1, D sets the top bound to y + 1, no vertical letter fixes y, and the same for L and R on x), then jump to the centre of the remaining rectangle. Both axes are halved at the same time, so you need about log2(max(W, H)) jumps. - [Stock Exchange Losses](https://mycodesolution.com/solution/stock-exchange-losses/index.html) · [FR](https://mycodesolution.com/fr/solution/stock-exchange-losses/index.html): Scan the values once, keeping the highest value seen so far. For every new value, the worst loss ending there is value - highestSoFar; keep the minimum of those differences, starting from 0, and print it, which gives a negative number or 0 when prices never go down. The whole solution is O(n) time and O(1) memory. - [Teads Sponsored Contest](https://mycodesolution.com/solution/teads/index.html) · [FR](https://mycodesolution.com/fr/solution/teads/index.html): The network in Teads is a tree, and the minimum number of steps to reach everyone from the best starting person is the tree's radius. For a tree, the radius equals ceil(diameter / 2), and the diameter is found with two traversals: from any node, find the farthest node u; from u, the farthest distance is the diameter D. Print (D + 1) / 2. - [Telephone Numbers](https://mycodesolution.com/solution/telephone-numbers/index.html) · [FR](https://mycodesolution.com/fr/solution/telephone-numbers/index.html): Telephone Numbers asks how many digit nodes are needed to store all the numbers in a prefix tree, where numbers that share a prefix share the same nodes. Insert each number into a trie digit by digit, creating a child only when it does not exist yet, and count every node you create; that count is the answer. - [The Gift](https://mycodesolution.com/solution/the-gift/index.html) · [FR](https://mycodesolution.com/fr/solution/the-gift/index.html): Sort the budgets in ascending order. If their sum is below the gift price, print IMPOSSIBLE; otherwise go through participants from poorest to richest and have each pay min(budget, remaining price / remaining participants) with integer division, subtracting each payment from the price. This minimises the largest contribution and prints the amounts already in ascending order. - [The Paranoid Android](https://mycodesolution.com/solution/paranoid-android/index.html) · [FR](https://mycodesolution.com/fr/solution/paranoid-android/index.html): Store, for every floor, the column the clones must reach: the elevator position on each floor and the exit position on the exit floor. Each turn, look only at the leading clone: if it walks left while its target is to its right, or right while its target is to its left, answer BLOCK; in every other case, including when there is no clone (floor -1), answer WAIT. - [There is no Spoon - Episode 1](https://mycodesolution.com/solution/apu-init-phase/index.html) · [FR](https://mycodesolution.com/fr/solution/apu-init-phase/index.html): Store the grid as rows of characters, then for every cell containing '0' scan to the right along its row and downward along its column until you hit the next '0'. Print the node's coordinates, the first node found on the right and the first node found below, using -1 -1 when a scan reaches the edge. With at most 30x30 cells this direct scan is far fast enough. - [Winamax Battle](https://mycodesolution.com/solution/winamax/index.html) · [FR](https://mycodesolution.com/fr/solution/winamax/index.html): Winamax Battle is a pure simulation of the card game War. Keep each deck as a queue, play rounds until one deck is empty, and on equal cards run a war where each player puts three extra cards face down and a fourth face up, repeating if they tie again. The winner takes player 1's played cards first, then player 2's, and if a player runs out of cards during a war the result is PAT. ### Hard - [Bender - Episode 2](https://mycodesolution.com/solution/bender-the-money-machine/index.html) · [FR](https://mycodesolution.com/fr/solution/bender-the-money-machine/index.html): The building has no cycles, so it is a directed acyclic graph and the richest route can be computed with dynamic programming: best(r) = money(r) + max(best(door1), best(door2)), where an exit counts as 0. Compute it once per room with memoisation (iteratively, to avoid deep recursion) and print best(0). - [Bender - Episode 3](https://mycodesolution.com/solution/bender-algorithmic-complexity/index.html) · [FR](https://mycodesolution.com/fr/solution/bender-algorithmic-complexity/index.html): Divide every measured time t by each candidate function f(n) (1, log n, n, n log n, n², n² log n, n³, 2ⁿ). If the data really grows like f, the ratios t/f(n) are almost constant, so print the candidate whose ratios have the smallest coefficient of variation (variance divided by the squared mean). - [CGX Formatter](https://mycodesolution.com/solution/cgx-formatter/index.html) · [FR](https://mycodesolution.com/fr/solution/cgx-formatter/index.html): Concatenate all input lines, then parse the text recursively into three kinds of elements: primitives, key-value pairs and parenthesised blocks, skipping spaces and tabs everywhere except inside quoted strings. Print the tree back with each block element on its own line, indented by four more spaces, with ';' after every element except the last. - [Genome Sequencing](https://mycodesolution.com/solution/genome-sequencing/index.html) · [FR](https://mycodesolution.com/fr/solution/genome-sequencing/index.html): First remove every subsequence that already appears inside another one, then try all permutations of the remaining strings (N ≤ 5, so at most 120 orders) and merge them left to right, each time overlapping the longest suffix of the current result with a prefix of the next string. The answer is the length of the shortest merged string over all orders. - [Shadows of the Knight - Episode 2](https://mycodesolution.com/solution/shadows-of-the-knight-2/index.html) · [FR](https://mycodesolution.com/fr/solution/shadows-of-the-knight-2/index.html): Search one axis at a time. Keep the range of columns that can still hold the bomb and jump to the mirror image of your position around the centre of that range: the perpendicular bisector of the move then cuts the range in half, and WARMER, COLDER or SAME tells you which half (or which exact column) to keep. Once one column remains, do the same along y, and avoid wasting turns at the grid edges by aiming at a quarter of the range instead of its centre when you stand on a border. - [Super Computer](https://mycodesolution.com/solution/super-computer/index.html) · [FR](https://mycodesolution.com/fr/solution/super-computer/index.html): Super Computer is the classic interval scheduling problem: turn each request into a half-open interval [J, J+D), sort the intervals by end day, and scan them once, keeping a request whenever it starts on or after the end of the last request you kept. The number of kept requests is the answer, and the greedy choice of 'earliest finish first' is provably optimal. - [Surface](https://mycodesolution.com/solution/surface/index.html) · [FR](https://mycodesolution.com/fr/solution/surface/index.html): To solve Surface, treat the map as a grid graph where water cells 'O' are connected to their four orthogonal neighbours, and answer each query with the size of the connected component containing the queried cell (0 if it is land). Use an iterative BFS flood fill rather than recursion, and label each lake once so repeated queries on the same lake cost nothing. - [TAN Network](https://mycodesolution.com/solution/tan-network/index.html) · [FR](https://mycodesolution.com/fr/solution/tan-network/index.html): Read the stops into a map from id to index, convert latitudes and longitudes from degrees to radians, and weight each directed route with the statement's equirectangular distance. Run Dijkstra from the start stop, rebuild the path with predecessor links and print the stop names in order, or IMPOSSIBLE if the destination is never reached. - [The Bridge - Episode 2](https://mycodesolution.com/solution/skynet-the-bridge/index.html) · [FR](https://mycodesolution.com/fr/solution/skynet-the-bridge/index.html): Simulate the motorbikes exactly as the game does and run a depth-first search over the commands each turn: try SPEED, JUMP, UP, DOWN and SLOW, prune any state with fewer than V bikes alive, and output the first command that leads to a state past the end of the road. Search first for a line that saves all bikes, then fall back to the minimum V. - [The Labyrinth](https://mycodesolution.com/solution/the-labyrinth/index.html) · [FR](https://mycodesolution.com/fr/solution/the-labyrinth/index.html): Keep your own copy of the map, initially all '?', and update it from the 5x5 view each turn. First explore: repeatedly BFS to the nearest unknown cell while treating walls and the control room as blocked. Once nothing is left to discover, BFS to the control room, then BFS back to the start; with the whole map known, the return path is the shortest one and fits the alarm countdown. ### Very hard - [The Resistance](https://mycodesolution.com/solution/the-resistance/index.html) · [FR](https://mycodesolution.com/fr/solution/the-resistance/index.html): Convert every dictionary word to its Morse code and insert those Morse strings into a trie over '.' and '-', storing how many words end at each node. Then compute ways[i], the number of ways to split the message suffix starting at i into words, from the end of the message backwards: walk the trie from position i and, at each node where words end, add count × ways[j]. The answer is ways[0]. ## Contact - Email: codingamesuccess@gmail.com