balanced parenthesis

What is balanced parenthesis? It is a set of complete parentheses that has an opening and closing parenthesis For example the following is balanced parenthesis


The following, however, is not


We can extend this concept to curly braces, square bracket, angle bracket etc. The …

Number of Sub-arrays With Odd Sum


Givin an array, return the number of odd-sum of sub arrays.

For more explanation see leetcode challenge.

My approaches

  1. First
    def numOfSubarrays(self, arr: List[int]) -> int:
        subs = [ 
            sum( arr[ i : j+1 ] ) …

complex sort in python

In python sort can be made with list.sort() or sorted(). The former is method of list and the latter is

Differences between the former and the latter are

list.sort() sorted()
change in place. return None return copy

Both have keyword arguments, key and reverse. key takes function to …

Find the Winner of the Circular Game

This coding challenge appeared in Leetcode April coding contest.

Caveats of this challenge
1. that index starts from 1
2. that cycle keeps chaning

I tried something like this but mine didn't pass the test, because I didn't take care of chaning cycle.

    def findTheWinner(self, n: …

for loop and while loop

In python for loop has fixed number of iteration unless specified otherwise.

Below is a common for loop.

nums = range(5)

for i in nums:

It will print five numbers.

In while loop you can maniuplate number of iteration by changing index. …