Interview Questions | Learn for Master - Part 11
  • LeetCode – Count Numbers with Unique Digits (Python)

    Given a non-negative integer n, count all numbers with unique digits, x, where 0 ≤ x < 10n.

    Given n = 2, return 91. (The answer should be the total numbers in the range of 0 ≤ x < 100, excluding [11,22,33,44,55,66,77,88,99])


    1. A direct way is to use the backtracking approach.
    2. Backtracking should contains three states which are (the current number, number of steps to get that number and a bitmask which represent which number is marked as visited so far in the current number). Start with state (0,0,0) and count all valid number till we reach number of steps equals to 10n.
    [Read More...]
  • LeetCode – Water and Jug Problem

    leetcode Water and Jug Problem

    You are given two jugs with capacities x and y litres. There is an infinite amount of water supply available. You need to determine whether it is possible to measure exactly z litres using these two jugs.

    Operations allowed:

    • Fill any of the jugs completely.
    • Empty any of the jugs.
    • Pour water from one jug into another till the other jug is completely full or the first jug itself is empty.

    Example 1: 


    Input: x = 2,

    [Read More...]
  • LeetCode-Coin Change Problem (Python)

    You are given coins of different denominations and a total amount of money amount. Write a function to compute the fewest number of coins that you need to make up that amount. If that amount of money cannot be made up by any combination of the coins, return -1.

    Example 1:
    coins = [1, 2, 5], amount = 11
    return 3 (11 = 5 + 5 + 1)

    Example 2:
    coins = [2], amount = 3
    return -1.

    You may assume that you have an infinite number of each kind of coin.

    [Read More...]
  • LeetCode – Next Permutation (Python)

    Implement next permutation, which rearranges numbers into the lexicographically next greater permutation of numbers.

    If such arrangement is not possible, it must rearrange it as the lowest possible order (ie, sorted in ascending order). The replacement must be in-place, do not allocate extra memory.

    Here are some examples. Inputs are in the left-hand column and its corresponding outputs are in the right-hand column.

    The solution is the Pandit’s algorithm

    1 Pandit’s algorithm
    The article in Wikipedia describes the algorithm invented by Narayana Pandit to changes the list in-place to generate the next permutation given a list or Array A.

    [Read More...]
  • Top java interview questions

    We share some most frequently and important java interview questions.

    Not only are these questions frequently asked by interviewers, but also

    that they are essential for you to master core Java.

    1. How do you implement your own Key Object for HashMap?

      To answer such as question, you probably should also get familiar with the concept of HashTable. Since HashTable use a hash function to map an object to the index of the underlying Array, you need to implement the hashcode method. As there can be conflicts: Two object generate the same hashcode,

    [Read More...]
Page 11 of 11« First...7891011