Leetcode
leetcode questions: Binary Search
bisect.bisect_left(a, x) https://dynalist.io/d/RWIGNj7DLlzkBed-3ZqhuBg_#z=cbr2Mkrig9KhE6Lxfwhm31IS O(logn) greater than or equal to the targeted value. If all elements are less than x, retur
read moreJava frequently used data structures and methods for leetcode
Arraydeclare int[] a = new int[100]; int[] b = {4,1,5}; array = new int[]{1,2,3}; two-dimensionalcodeint a[][] = {{1,2}, {3,4}}
read moreleetcode: Trie
Basic A Trie is a special form of a Nary tree. Typically, a trie is used to store strings. Each Trie node represents a string (a prefix). Each node might have several children nodes while the path
read moreleetcode questions: Bit
common tricks x & (-x) to isolate/get the rightmost 1-bit This operation reverts all bits of x except the rightmost 1-bit. Hence, x and -x have just one bit in common - the rightmost 1-bi
read moreleetcode: mini spanning tree, single src shortest path, topological
Minimum spanning tree A minimum spanning tree is a spanning tree with the minimum possible total edge weight in a “weighted undirected graph”. [Min Cost to Connect All Points - LeetCode](https://
read moreleetcode questions: Backtracking
Template def backtrack(candidate): if find_solution(candidate): output(candidate) return # iterate all possible candidates. for next_candidate in list_of_candida
read moreleetcode questions: BFS
BFS Template /** * Return the length of the shortest path between root and target node. */ int BFS(Node root, Node target) { Queue<Node> queue; // store all nodes which are waiting
read moreleetcode questions: DFS
DFS Templates Template 1: /* * Return true if there is a path from cur to target. */ boolean DFS(Node cur, Node target, Set<Node> visited) { return true if cur is target; for (ne
read moreleetcode questions: dynamic programming
Intro Good video: Dynamic Programming - Learn to Solve Algorithmic Problems & Coding Challenges - YouTube DP is a style of coding where you store t
read moreLeetcode: LinkedList in Python
create a dummy nodeMerge two linked lists.# Definition for singly-linked list. # class ListNode: # def __init__(self, x): # self.val = x # self.next = Noneclass
read morePython list/dict functions for leetcode
Listlen(array) : length of array list.indexof(obj)enumerate(array) : adds counter at the beginning. for count, item in enumberate(['x','y','z']) # 0x 1y 2z`range(0,len
read morePython String functions for leetcode
print(f'best RF score: {grid.best_score_:.3f}') str.index(sub[,start[,end]]) str.strip() remove spaces at the beginning and the end strip(str-not-want)lower() print(str.
read moreLeetcode: Array questions with Python
134.Gas StationThere are N gas stations along a circular route, where the amount of gas at station i is gas[i]. You have a car with an unlimited gas tank and it costs cost[i] of gas to travel f
read more