Giter Club home page Giter Club logo

interviewpen's People

Contributors

abhinvsinh avatar bephrem1 avatar bzaghalarov avatar ccffsun avatar chellitorvic avatar evinaik avatar lavishsaluja avatar mayank23 avatar northerndemon avatar nyjalusc avatar pranavdave893 avatar thangaraj14 avatar vineetpalan avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

interviewpen's Issues

Update declaration of "UndirectedGraphNode"

The updated declaration of class "UndirectedGraphNode" is as follows:

class Node {
    public int val;
    public List<Node> neighbors;

    public Node() {}

    public Node(int _val,List<Node> _neighbors) {
        val = _val;
        neighbors = _neighbors;
    }
};

Line 67 is == instead of !=

// Skip non-empty entries. They already have a value in them.
  if (board[row][col] == EMPTY_ENTRY) {
    return solveSudokuCell(row, col + 1, board);
  }

Error in formula

Sir, according to me you have made a typo error in writing the formula for g(n) in the inner loop, as the formula should be g(i)+=g(j-1)*g(n-j) but you have write g(i)+=g(j-i)*g(i-j), sir if I am wrong then please make me clear, else kindly edit the code
Thanks

Go from O(n) to O(1) in is_palindrome

Love your videos!

Right now your isPalindrome function is taking O(n) work to determine if a string is a palindrome. However, we don't need to do that because the function can be built recursively and pre-computed. In other words once you know that "bcedfcb" is not a palindrome, you don't need to take O(n) time for the sequence "abcedfcba" (since it's the same sequence with two letters outside.

I believe this change takes your big O complexity from O(n*2^n) to just O(2^n) since there are 2^n ways to partition a string of length n and its now doing constant time work in each partition (previously it was doing O(n) work). Essentially you have O(n^2) to precompute all palindromes and O(2^n) to calculate all partitions. O(n^2 + 2^n) -> O(2^N)

Basically I'm suggesting to use the isPalindrome function from this question: https://leetcode.com/problems/longest-palindromic-substring/solution/

Here is my code:

class Solution:
    def partition(self, s: str) -> List[List[str]]:
        n = len(s)

        # This precomputers all palindromes in O(n^2) time given total complexity O(n^2 + 2^n) = O(2^n)
        # Your solutions does n work  (instead of O(1) on each backtrace) making it O(n*2^n) in the worst case
        is_palindrome = [[None] * n for _ in range(n)]
        for i in range(n - 1, -1, -1):
            for j in range(i, n):
                if i == j:
                    is_palindrome[i][j] = True
                elif i + 1 == j:
                    is_palindrome[i][j] = s[i] == s[j]
                else:
                    if s[i] != s[j]:
                        is_palindrome[i][j] = False
                    else:
                        is_palindrome[i][j] = is_palindrome[i + 1][j - 1]
        
        solutions = []
        def _split(path, start):
            if start == n:
                solutions.append(path[:])
                return
            
            for end in range(start, n):
                if is_palindrome[start][end]:
                    path.append(s[start:end+1])
                    _split(path, end + 1)
                    path.pop()
        
        _split([], 0)
        return solutions

Videos Missing Code

Balanced Parentheses: https://www.youtube.com/watch?v=CCyEXcNamC4
How To Permute A String: https://www.youtube.com/watch?v=GCm7m5671Ps
IP Address Decomposition: https://www.youtube.com/watch?v=KU7Ae2513h0
KMP Substring Search: https://www.youtube.com/watch?v=BXCEFAzhxGY
Test If A Binary Tree Is Symmetric: https://www.youtube.com/watch?v=XV7Sg2hJO3Q
Dutch National Flag Problem: https://www.youtube.com/watch?v=ER4ivZosqCg
0/1 Knapsack Problem: https://www.youtube.com/watch?v=xCbYmUPvc2Q
Depth First & Breadth First Graph Search: https://www.youtube.com/watch?v=TIbUeeksXcI
Reverse A Singly Linked List: https://www.youtube.com/watch?v=O0By4Zq0OFc
Middle of A Linked List: https://www.youtube.com/watch?v=UitXxwVeOrk
Compute All Mnemonics For A Phone Number: https://www.youtube.com/watch?v=a-sMgZ7HGW0
Reverse The Digits of An Integer: https://www.youtube.com/watch?v=ZQQoHr-2stA

Bug in SearchALinkedListWithJumps

While boxed type Integer is stored in a heap, it is still immutable. You can see in the Integer class sources that the primitive value it wraps is declared as final here.

Another thing is that objects are indeed passed to methods as references, but that references are copied to a local variable (parameter) of a method.
So currentOrder += 1 is the same as currentOrder = currentOrder + 1, and JVM, in that case, unboxes currentOrder to a primitive value, performs addition and then boxes result into a new instance of Integer. Then the reference to this new object is assigned to currentOrder, overriding the initial value of it. But it held just a copy of a reference passed, so the original variable used as an argument remains the same, pointing to an old boxing object instance.

This can be observed from a simple example here or by using the following list to run the program:

ListNode a = new ListNode();
ListNode b = new ListNode();
ListNode c = new ListNode();
a.next = b;
b.next = c;
a.jump = c;

Result should be a:0 b:2 c:1, but it is a:0 b:1 c:1.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.