Skip to content

olegsobchuk/simple_task

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

62 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Simple Task

List of tasks

  1. Find the last non-repeating character in a given string. If all characters repeat, return an empty string.

    Example:

    > nonRepeat('candy canes do taste yummy')
    > 'u'
    

    Golang | Python | Ruby

  2. You're assembling a custom mechanical keyboard. Each required part has a delivery time in days and an assembly time in hours. You can only assemble a part after it arrives, and you can only work on one part at a time. Given an array of parts where each part is { name, arrivalDays, assemblyHours }, return the minimum total hours needed to finish assembling all parts, starting from hour 0.

    Example:

    minAssemblyTime([
      { name: "keycaps", arrivalDays: 1, assemblyHours: 2 },
      { name: "switches", arrivalDays: 2, assemblyHours: 3 },
      { name: "stabilizers", arrivalDays: 0, assemblyHours: 1 },
      { name: "PCB", arrivalDays: 1, assemblyHours: 4 },
      { name: "case", arrivalDays: 3, assemblyHours: 2 }
    ])
    
    > 74
    
    

    Golang | Python | Ruby TBD

  3. Given an array of audio file durations, write a function to group the files into playlists such that each playlist's total duration does not exceed a given limit maxDuration. Return an array of playlists, where each playlist is an array of file durations. Try to minimize the number of playlists.

    Example:

    const files = [120, 90, 60, 150, 80];
    const maxDuration = 200;
    
    groupAudioFiles(files, maxDuration)
    > [[150], [120,80], [90,60]]
    
    groupAudioFiles(files, 160)
    > [[150], [120], [90,60], [80]]
    
    

    Golang | Python | Ruby TBD

  4. Given an array arr representing the positions of monsters along a straight line, and an integer d representing the minimum safe distance required between any two monsters, write a function to determine if all monsters are at least d units apart. If not, return the smallest distance found between any two monsters. If all monsters are safely spaced, return -1.

    Examples:

    let monsters = [3, 8, 10, 15];
    let d = 6;
    minMonsterDistance(bees, d)
    > 2
    
    minMonsterDistance([5, 9, 14, 18], 4)
    > -1
    
    

    Golang TBD | Python | Ruby TBD

  5. Write a generator function createLaundryItem() that returns an object representing a laundry item. This object should have a method nextCycle() which, when called, advances the item through a series of laundry cycles in order: "soak", "wash", "rinse", "spin", and "dry". After the final cycle, subsequent calls to nextCycle() should return "done".

    Example:

    let towel = createLaundryItem();
    
    console.log(towel.nextCycle()); // "soak"
    console.log(towel.nextCycle()); // "wash"
    console.log(towel.nextCycle()); // "rinse"
    console.log(towel.nextCycle()); // "spin"
    console.log(towel.nextCycle()); // "dry"
    console.log(towel.nextCycle()); // "done"
    console.log(towel.nextCycle()); // "done"
    
    

    Golang | Python | Ruby TBD

  6. Given an array of order objects for a restaurant, each with a table number and a list of ordered items, write a function that returns an object mapping each table number to a summary of how many times each item was ordered at that table. Extra credit: Could you go so far as to make this a restaurant management game?

    Example:

    const orders = [
      { table: 1, items: ["burger", "fries"] },
      { table: 2, items: ["burger", "burger", "fries"] },
      { table: 1, items: ["salad"] },
      { table: 2, items: ["fries"] }
    ];
    
    > orderSummary(orders)
    {
      1: { burger: 1, fries: 1, salad: 1 },
      2: { burger: 2, fries: 2 }
    }
    // or, string output format:
    "Table 1 ordered 1 burger, 1 fries, and 1 salad. Table 2 ordered 2 burgers and 2 fries."
    
    

    Golang | Python | Ruby TBD

  7. Given an array of side lengths, write a function to determine they can form a hexagon with three side-length pairs (as in, three pairs of equal sides needed). Return true if possible.

    Examples:

    canFormHexagon([2, 3, 8, 8, 2, 3])
    > true
    
    canFormHexagon([1, 2, 3, 4, 5, 6])
    > false
    
    canFormHexagon([2, 2, 2, 2, 2, 2, 2])
    > false
    
    

    Golang | Python | Ruby TBD

  8. Given a multi-line string and a sequence of Vim navigation commands (h for left, j for down, k for up, and l for right), and starting at the top-left character, write a function that processes the commands and returns the character under the cursor. If the cursor tries to move out of bounds, keep it at the last valid position.

    Example:

    const string = `Hello, world!
    how are ya?`; // or "Hello, world!\nhow are ya?"
    const commands = 'jlhll';
    
    getCharAfterVimCommands(string, commands)
    > 'w'
    
    

    Golang | Python TBD | Ruby TBD

  9. Given an array of strings representing a sequence of traffic light states ("red" for stop, "green" for go, "yellow" for slow), write a function that returns true if the sequence could represent a valid state machine for a standard traffic light. The only valid transitions are: red to green, green to yellow, and yellow to red.

    Example:

    > isValidTrafficSequence(["red", "green", "yellow", "red", "green"])
    > true
    
    > isValidTrafficSequence(["red", "yellow", "green"]);
    > false
    
    > isValidTrafficSequence([])
    > true
    
    

    Golang | Python TBD | Ruby TBD

  10. Imagine a simplified version of the game Battleship played on a 2D grid. The grid represents the sea, and each cell can either be empty (.) or contain a part of a ship (X). Ships are placed horizontally or vertically, and there are no adjacent ships. Given a grid, count the number of battleships in it. Extra credit: can you make a layout generator for the game given these rules?

    Example:

    const ships = [
      ['X', 'X', '.', 'X'],
      ['.', '.', '.', 'X'],
      ['.', '.', '.', 'X'],
      ['.', '.', '.', '.'],
    ];
    
    numberOfShips(ships)
    > 2
    
    

    Golang | Python TBD | Ruby TBD

  11. For an array of numbers, generate an array where for every element, all neighboring elements are added to itself, and return the sum of that array.

    Examples:

    []               -> 0
    [1]              -> 1
    [1, 4]           -> 10 // (1+4 + 4+1)
    [1, 4, 7]        -> 28 // (1+4 + 4+1+7 + 7+4)
    [1, 4, 7, 10]    -> 55
    [-1, -2, -3]     -> -14
    [0.1, 0.2, 0.3]  -> 1.4
    [1,-20,300,-4000,50000,-600000,7000000] -> 12338842
    
    

    Golang TBD | Python | Ruby TBD

  12. Given an array of strings representing the names of monarchs and their ordinal numbers, write a function that returns the list of names sorted first by name and then by their ordinal value (in Roman numerals), in ascending order.

    Example:

    > sortMonarchs(["Louis IX", "Louis VIII", "Philip II", "Philip I"])
    > ["Louis VIII", "Louis IX", "Philip I", "Philip II"]
    
    > sortMonarchs(["George VI", "George V", "Elizabeth II", "Edward VIII"])
    > ["Edward VIII", "Elizabeth II", "George V", "George VI"]
    
    

    Golang | Python TBD | Ruby TBD

  13. Turn an array of integers into a nested array. You can think of this as the opposite of flattening an array!

    Examples:

    nestArray([1, 2, 3, 4])
    > [1, [2, [3, [4]]]]
    
    nestArray([1])
    > [1]
    
    

    Golang TBD | Python | Ruby TBD

  14. Write a function that determines if a number is abundant, deficient, perfect, or amicable.

    Examples:

    whatKindOfNumber(6)
    > 'perfect'
    
    whatKindOfNumber(12)
    > 'abundant'
    
    whatKindOfNumber(4)
    > 'deficient'
    

    Golang | Python TBD | Ruby TBD

  15. Given the non-negative integer n , output the value of its hyperfactorial. Don't worry about outputs exceeding your language's integer limit.

    Examples:

    > hyperfactorial(0)
    > 1
    
    > hyperfactorial(2)
    > 4
    >
    > hyperfactorial(3)
    > 108
    
    > hyperfactorial(7)
    > 3319766398771200000
    

    Golang | Python TBD | Ruby TBD

  16. You're building a tool that tracks component edits and groups them into a changelog. Given an array of edit actions, each with a timestamp and a component name, return an array of grouped changelog entries. Edits to the same component within a 10-minute window should be merged into one changelog entry, showing the component name and the range of timestamps affected.

    Example:

    const edits = [
      { timestamp: "2025-10-06T08:00:00Z", component: "Header" },
      { timestamp: "2025-10-06T08:05:00Z", component: "Header" },
      { timestamp: "2025-10-06T08:20:00Z", component: "Header" },
      { timestamp: "2025-10-06T08:07:00Z", component: "Footer" },
      { timestamp: "2025-10-06T08:15:00Z", component: "Footer" },
    ];
    
    > groupChangelogEdits(edits)
    > [
        {
            "component": "Footer",
            "start": "2025-10-06T08:07:00Z",
            "end": "2025-10-06T08:15:00Z"
        },
        {
            "component": "Header",
            "start": "2025-10-06T08:00:00Z",
            "end": "2025-10-06T08:05:00Z"
        },
        {
            "component": "Header",
            "start": "2025-10-06T08:20:00Z",
            "end": "2025-10-06T08:20:00Z"
        }
    ]
    

    Golang TBD | Python | Ruby TBD

  17. Given a CSV string where each row contains a name, age, and city (and values may be quoted, have embedded commas or escaped quotes), write a function that parses the CSV and outputs a formatted list of strings in the form: "Name, age Age, from City". Handle quoted fields containing commas and escaped quotes.

    Example:

    const csv = 'name,age,city\n"Ryu, Mi-yeong",30,"Seoul"\nZoey,24,"Burbank"'
    
    csvToList(csv)
    >
    - Ryu, Mi-yeong, age 30, from Seoul
    - Zoey, age 24, from Burbank
    

    Golang | Python TBD | Ruby TBD

  18. Given a string str and an array of positive integers widths, write a function that splits the string into lines, each with the exact number of characters as specified by the corresponding width. Return an array of the substrings. Use the last width for any remaining characters if the array is shorter than needed.

    Example:

    const str = "Supercalifragilisticexpialidocious";
    const widths = [5, 9, 4];
    
    > splitByWidths(str, widths);
    > ['Super', 'califragi', 'list', 'icex', 'pial', 'idoc', 'ious']
    

    Golang TBD | Python | Ruby TBD

  19. Given a field represented as an array of 0s and 1s, where 1 means that position needs protection, you can place a scarecrow at any index, and each scarecrow protects up to k consecutive positions centered around itself (for example, for k = 3, a scarecrow at i protects i-1, i, and i+1). Return the minimum set of indices where scarecrows should be placed so that all the positions with 1 are protected. You can assume k is an odd number (or make up what happens if it's even).

    Examples:

    let field = [1, 1, 0, 1, 1, 0, 1];
    let k = 3;
    
    placeScarecrows(field, k);
    > [1, 4, 6]
    
    placeScarecrows([1, 0, 1, 1, 0, 1], k)
    > [1, 4]
    
    placeScarecrows([1, 1, 1, 1, 1], 1)
    > [0, 1, 2, 3, 4]
    

    Golang | Python TBD | Ruby TBD

  20. Given he current position of a knight as [row, col] in an 8x8 chess board represented as a 2D array, write a function to return all valid moves the knight can make. Extra credit: Do this for every chess piece!

    Example:

    knightMoves([4, 4])
    > [[2, 3], [2, 5], [3, 2], [3, 6], [5, 2], [5, 6], [6, 3], [6, 5]]
    
    knightMoves([0, 0])
    > [[1, 2], [2, 1]]
    
    knightMoves([1, 2])
    > [[0, 0], [0, 4], [2, 0], [2, 4], [3, 1], [3, 3]]
    

    Golang TBD | Python TBD | Ruby

  21. You are given two sorted arrays, a and b, where a has a large enough size buffer at the end to hold b (which can be spaces, zeroes, or nulls). Write a function to merge b into a in sorted order.

    Example:

    let a = [1, 3, 5, 0, 0, 0];
    let b = [2, 4, 6];
    
    > merge(a, b)
    > [1, 2, 3, 4, 5, 6]
    

    Golang TBD | Python TBD | Ruby

  22. Given a positive integer n, write a function that returns an array containing all integers from 1 to n, where each integer i appears exactly i times in the result. For example, 3 should appear 3 times, 5 should appear 5 times, and so on. The order of the integers in the output array does not matter.

    Example:

    > repeatedIntegers(4)
    > [1, 2, 2, 3, 3, 3, 4, 4, 4, 4]
    

    Golang TBD | Python TBD | Ruby TBD

  23. Given an array of meal prep tasks for Thanksgiving, where each task is represented as [taskName, startTime, endTime], return the maximum number of non-overlapping tasks you can complete, along with the names of the chosen tasks in the order they were selected. Task times are inclusive of start but exclusive of end.

    Example:

    const tasks = [
      ["Make Gravy", 10, 11],
      ["Mash Potatoes", 11, 12],
      ["Bake Rolls", 11, 13],
      ["Prep Salad", 12, 13]
    ];
    
    maxMealPrepTasks(tasks)
    > {
        count: 3,
        chosen: ["Make Gravy", "Mash Potatoes", "Prep Salad"]
      }
    

    Golang TBD | Python TBD | Ruby TBD

  24. There are 16 basic HTML Colors. Write a program to output them in ascending order by HEX value. Don't use any built-in sorting methods!

    Example output:

    000000
    000080
    0000FF
    008000
    008080
    00FF00
    00FFFF
    800000
    800080
    808000
    808080
    C0C0C0
    FF0000
    FF00FF
    FFFF00
    FFFFFF
    

    Golang TBD | Python TBD | Ruby TBD

  25. Make a data structure for a deck of cards, and implement a shuffle() method, and a draw(n) method (where you draw n cards). Calling draw() when the deck is empty returns an empty array.

    Example usage:

    const deck = new Deck();
    deck.shuffle();
    console.log(deck.draw(5)); // Example: ['10♠', 'K♥', '3♣', 'J♦', '7♠']
    console.log(deck.draw(5).length); // 5
    console.log(deck.draw(2)); // Example: ['5♣', 'A♠']
    

    Golang TBD | Python TBD | Ruby TBD

  26. Write a function to generate a Latin Square given a positive integer n. The values can be any n distinct values, and don't have to be consistent for different n.

    Examples:

    latinSquare(1)
    [[1]]
    
    latinSquare(2)
    [[1, 2], [2, 1]]
    
    latinSquare(4)
    [[1, 2, 3, 4], [2, 1, 4, 3], [3, 4, 1, 2], [4, 3, 2, 1]]
    

    Golang TBD | Python TBD | Ruby TBD

  27. An alternating array is a list of any length in which two (not necessarily different) values are alternating (all even-indexed items are equal, and all odd-indexed items are equal). Given an array, return true if it is alternating.

    Examples:

    []             -> True
    [1]            -> True
    [1,1]          -> True
    [1,2,1]        -> True
    [10,5,10,5,10] -> True
    [2,2,3,3]      -> False
    [5,4,3,5,4,3]  -> False
    

    Golang TBD | Python TBD | Ruby TBD

  28. Given a string that contains only digits from 0 to 9 and a number n, replace each consecutive run of n with its length.

    Examples:

    > replaceRepeats('1234500362000440', 0)
    > 1234523623441
    
    > replaceRepeats('000000000000', 0)
    > 12
    
    > replaceRepeats('123456789', 1)
    > 123456789
    

    Golang TBD | Python TBD | Ruby TBD

  29. Given an integer array nums, sum each element in the array in order. You are allowed to use at most one reset during the run: when you reset, your current score becomes 0 and you continue with the next elements. Return the maximum score you can end with.

    Example:

    > maxScoreWithOneReset([2, -1, 2, -5, 2, 2]) // reset after -5
    > 4
    
    > maxScoreWithOneReset([4, -10, 3, 2, -1, 6]) // reset after -10
    > 10
    
    > maxScoreWithOneReset([-50, -2, -3]) // reset after -3
    > 0
    

    Golang TBD | Python TBD | Ruby TBD

  30. Given an array of objects representing bears in a forest, each with a name and hunger level, return the names of all bears whose hunger level is above the forest average, sorted alphabetically. In how few lines can you do this one?

    Example:

    const bears = [
      { name: 'Baloo', hunger: 6 },
      { name: 'Yogi', hunger: 9 },
      { name: 'Paddington', hunger: 4 },
      { name: 'Winnie', hunger: 10 },
      { name: 'Chicago', hunger: 20 },
    ];
    
    hungryBears(bears)
    > ['Chicago', 'Winnie']
    

    Golang TBD | Python TBD | Ruby TBD

  31. Given a string str, find a contiguous substring of length 10 whose characters can be bijectively mapped to the moves {U,D,L,R,B,A} so that the substring decodes to the Konami code "UUDDLRLRBA" (a character always maps to the same move, and two different moves can’t share a character). Return a valid mapping as an object.

    Example:

    konamiMapping("xx2233454590yy11110")
    > { "0": "A", "2": "U", "3": "D", "4": "L", "5": "R", "9": "B" }
    
    konamiMapping("sduwahoda22ii0d0dbn")
    > { "0": "L", "2": "U", "i": "D", "d": "R", "b": "B", "n": "A" }
    

    Golang TBD | Python TBD | Ruby TBD

  32. February 2026 is a perfect month! Write a function that returns the closest previous and next perfect month around the given Gregorian year.

    Examples:

    nearestPerfectMonths(2025)
    > { prev: "2021-02", next: "2026-02" }
    
    nearestPerfectMonths(2026)
    > { prev: "2026-02", next: "2027-02" }
    

    Golang TBD | Python TBD | Ruby TBD

  33. Given an integer array and a number n, move all of the ns to the end of the array while maintaining the relative order of the non-ns. Bonus: do this without making a copy of the array!

    Example:

    $ moveNums([0,2,0,3,10], 0)
    $ [2,3,10,0,0]
    

    Golang TBD | Python TBD | Ruby TBD

  34. You have a 2D grid of numbers. Write a function that zooms in by an integer factor k >= 2 by turning each cell into a k x k block with the same value, returning the bigger grid.

    Examples:

    zoom([[1,2],[3,4]], 2)
    [
      [1,1,2,2],
      [1,1,2,2],
      [3,3,4,4],
      [3,3,4,4]
    ]
    
    zoom([[7,8,9]], 3)
    [
      [7,7,7,8,8,8,9,9,9],
      [7,7,7,8,8,8,9,9,9],
      [7,7,7,8,8,8,9,9,9]
    ]
    
    zoom([[1],[2]], 3)
    [
      [1,1,1],
      [1,1,1],
      [1,1,1],
      [2,2,2],
      [2,2,2],
      [2,2,2]
    ]
    

    Golang TBD | Python TBD | Ruby TBD

  35. Given an array of integers, find the contiguous subarray that has the largest sum and return that sum. A subarray must contain at least one element. If all elements are negative, return the largest (least negative) value. If you need a hint, look up Kadane's Algorithm!

    Examples:

    > maxSubarraySum([-2, 1, -3, 4, -1, 2, 1, -5, 4])
    6
    > maxSubarraySum([5])
    5
    > maxSubarraySum([-1, -2, -3, -4])
    -1
    > maxSubarraySum([5, 4, -1, 7, 8])
    23
    

    Golang TBD | Python TBD | Ruby TBD

  36. You are given a string consisting of lowercase words, each separated by a single space. Determine how many vowels appear in the first word. Then, reverse each following word that has the same vowel count.

    Examples:

    flippedy("cat and mice")
    > "cat dna mice"
    
    flippedy("banana healthy")
    > "banana healthy"
    

    Golang TBD | Python TBD | Ruby TBD

  37. Find the majority element in an array (one that appears more than n/2 times) in O(n) time and O(1) space without hashmaps. Hint: the Boyer-Moore Voting algorithm might help if you can't figure this one out!

    Example:

    > majorityElement([2, 2, 1, 1, 2, 2, 1, 2, 2])
    2
    
    > majorityElement([3, 3, 4, 2, 3, 3, 1])
    3
    

    Golang TBD | Python TBD | Ruby TBD

  38. Given a string s consisting only of 'a' and 'b', you may swap adjacent characters any number of times. Return the minimum number of adjacent swaps needed to transform s into an alternating string, either "ababab..." or "bababa...", or return -1 if it's impossible.

    Example:

    minSwapsToAlternate('aabb')
    1
    
    minSwapsToAlternate('aaab')
    -1
    
    minSwapsToAlternate('aaaabbbb')
    6
    

    Golang TBD | Python TBD | Ruby TBD

  39. You're given a 2D grid representing a city where each cell is either empty (0), a fire station (1), or a building (2). Fire stations can serve buildings based on horizontal + vertical moves only. Return a 2D grid where each cell shows the minimum distance to the nearest fire station.

    Examples:

    > fireStationCoverage([
    [2, 0, 1],
    [0, 2, 0],
    [1, 0, 2]
    ])
    > [[2, 1, 0],
    [1, 2, 1],
    [0, 1, 2]]
    
    > fireStationCoverage([
    [1, 0, 0, 1],
    [0, 0, 0, 0],
    [0, 0, 0, 0],
    [1, 0, 0, 1]
    ])
    > [[0, 1, 2, 0],
    [1, 2, 2, 1],
    [1, 2, 2, 1],
    [0, 1, 2, 0]]
    

    Golang TBD | Python TBD | Ruby TBD

  40. Given a text string and a pattern, implement a fuzzy string search using the Bitap algorithm that finds all positions in the text where the pattern matches with at most k errors (insertions, deletions, or substitutions). Return an array of objects containing the position and the number of errors at that match.

    Example:

    > fuzzySearch("the cat sat on the mat", "cat", 0);
    > [{ position: 4, errors: 0 }]
    
    > fuzzySearch("cassidoo", "cool", 1);
    > []
    
    > fuzzySearch("cassidoo", "cool", 3);
    > [{ "position": 3, "errors": 3 }, { "position": 4, "errors": 2 }]
    

    Golang TBD | Python TBD | Ruby TBD

  41. Given an integer n, return all unique combinations of Perrin numbers (up to and including the nth Perrin number) that sum to a target value k, where each Perrin number can be used at most once. Return the combinations sorted in ascending order.

    Example:

    > perrinCombinations(7, 12)
    [[0,2,3,7],[0,5,7],[2,3,7],[5,7]]
    
    > perrinCombinations(6, 5)
    [[0,2,3],[0,5],[2,3],[5]]
    

    Golang TBD | Python TBD | Ruby TBD

  42. You are given a file system represented as an object where keys are absolute paths and values are either null (real file/directory) or a string (a symlink pointing to another path). Write a function that resolves a given path to its real destination, following symlinks along the way. If a symlink chain forms a cycle, return null.

    Example:

    const fs = {
    "/a": "/b",
    "/b": "/c",
    "/c": null,
    "/loop1": "/loop2",
    "/loop2": "/loop1",
    "/real": null,
    "/alias": "/real",
    };
    
    resolvePath(fs, "/a");      // "/c"
    resolvePath(fs, "/alias");  // "/real"
    resolvePath(fs, "/loop1");  // null
    resolvePath(fs, "/real");   // "/real"
    

    Golang TBD | Python TBD | Ruby TBD

  43. You're building a pizza ordering system that enforces strict ingredient layering rules. Given an array of pizza layers (bottom to top) and a set of rules where each rule states that ingredient A must appear somewhere below ingredient B, write a function that determines whether the pizza is valid. If any rule is violated, return the pair [A, B] that was violated first (in the order the rules are given). If the pizza is valid, return true.

    Examples:

    const layers = ["dough", "sauce", "cheese", "pepperoni", "basil"];
    const rules = [
    ["sauce", "cheese"],
    ["cheese", "pepperoni"],
    ["dough", "basil"],
    ];
    const rules2 = [
    ["cheese", "pepperoni"],
    ["cheese", "sauce"], // "it's under the sauce"
    ];
    
    validatePizza(layers, rules);
    > true
    
    validatePizza(layers, rules2);
    > ['cheese', 'sauce']
    

    Golang TBD | Python TBD | Ruby TBD

  44. Given a string s containing letters and ? wildcards (that can match any letter), and a target pattern string pattern, rearrange the entire string however you like. Return the maximum number of non-overlapping copies of pattern that can appear in the rearranged result.

    Example:

    maxPatternCopies("abcabc???", "ac")  // 3
    
    maxPatternCopies("aab??", "aab")  // 1
    
    maxPatternCopies("??????", "abc")  // 2
    

    Golang TBD | Python TBD | Ruby TBD

  45. You are given a 2D grid where 1 represents an intact tile and 0 represents a broken tile. A "broken region" is a group of connected 0s (connected horizontally or vertically). Find the minimum number of tiles you need to repair to ensure no broken region has an area larger than k.

    Examples:

    const grid = [
    [1, 0, 0, 1],
    [1, 0, 0, 1],
    [1, 1, 0, 1],
    [0, 1, 1, 1],
    ];
    const k = 2;
    
    let newGrid = [
    [1, 0, 0, 1],
    [1, 0, 0, 1],
    [1, 1, 0, 1],
    [0, 0, 1, 1],
    ];
    let newK = 1;
    
    minRepairs(grid, k)
    > 2
    
    minRepairs(newGrid, newK)
    > 3
    

    Golang TBD | Python TBD | Ruby TBD

  46. Given an array of positive integers, find the length of the longest subsequence where every adjacent pair of elements in the subsequence is coprime (where the greatest common divisor, or GCD, is 1).

    Example:

    longestCoprimeSubsequence([6, 12, 4, 8])
    > 1 // none are coprime
    
    longestCoprimeSubsequence([4, 3, 6, 9, 7, 2])
    > 4 // [4, 3, 7, 2], where gcd(4,3)=1, gcd(3,7)=1, gcd(7,2)=1
    

    Golang TBD | Python TBD | Ruby TBD

  47. Given a string s consisting of letters, convert each character to its opposite case that is, change every lowercase letter to uppercase, and every uppercase letter to lowercase. Bonus: add an "alternate" parameter that converts the whole string to AlTeRnAtE cAsE!

    Examples:

    let alternating = true
    
    toggleChar("Hello, world!")
    > "hELLO, WORLD!"
    
    toggleChar("HeheHeheHEheheHeH")
    > "hEHEhEHEheHEHEhEh"
    
    toggleChar("This will be alternated", alternating)
    > "ThIs WiLl Be AlTeRnAtEd"
    

    Golang TBD | Python TBD | Ruby TBD

  48. Given a queue of customer names and an integer n, move every nth customer to the end of the line while preserving relative order otherwise.

    Example:

    shuffleLine(["Ada", "Ben", "Cam", "Diya", "Eli", "Fay"], 3);
    > ['Ada', 'Ben', 'Diya', 'Eli', 'Cam', 'Fay']
    // Every 3rd customer is moved to the end, so "Cam" and "Fay"
    // are moved after the others, preserving their original order.
    
    shuffleLine(["A", "B", "C", "D", "E"], 2);
    > ['A', 'C', 'E', 'B', 'D']
    
    shuffleLine(["Mo", "Noah", "Oli"], 1);
    > ['Mo', 'Noah', 'Oli']
    

    Golang TBD | Python TBD | Ruby TBD

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors