Python

Solve The Triangle of Odd Numbers using Python

The challenge Given the triangle of consecutive odd numbers: Calculate the row sums of this triangle from the row index (starting at index 1) e.g.:… Read More »Solve The Triangle of Odd Numbers using Python

“Who likes it” code Challenge in Python

The Challenge You probably know the “like” system from Facebook and other pages. People can “like” blog posts, pictures or other items. We want to… Read More »“Who likes it” code Challenge in Python

Solving Tribonacci Sequence with Python

The challenge As the name may already reveal, it works basically like a Fibonacci, but summing the last 3 (instead of 2) numbers of the… Read More »Solving Tribonacci Sequence with Python

The Casino Chips Problem Solved with Python

The challenge You are given three piles of casino chips: white, green and black chips: the first pile contains only white chips the second pile… Read More »The Casino Chips Problem Solved with Python

Check if Isogram using Python

The challenge An isogram is a word that has no repeating letters, consecutive or non-consecutive. Implement a function that determines whether a string that contains… Read More »Check if Isogram using Python

Find the Longest Common Prefix using Python

The challenge Write a function to find the longest common prefix string amongst an array of strings. If there is no common prefix, return an… Read More »Find the Longest Common Prefix using Python

Count and Say with Python

The challenge he count-and-say sequence is the sequence of integers with the first five terms as following: 1. 1 2. 11 3. 21 4. 1211… Read More »Count and Say with Python

The Plus One problem solved with Python

The challenge Given a non-empty array of digits representing a non-negative integer, increment one to the integer. The digits are stored such that the most significant digit is at… Read More »The Plus One problem solved with Python

Solving the Single Number problem in Python

The challenge Given a non-empty array of integers, every element appears twice except for one. Find that single one. Note: Your algorithm should have a linear runtime complexity. Could… Read More »Solving the Single Number problem in Python

Rotate a Matrix List in Python

The challenge You are given an n x n 2D matrix representing an image. Rotate the image by 90 degrees (clockwise). Note: You have to rotate the image in-place, which… Read More »Rotate a Matrix List in Python

Find the Intersection of Two Arrays in Python

The challenge Given two arrays, write a function to compute their intersection. Example 1: Input: nums1 = [1,2,2,1], nums2 = [2,2] Output: [2,2] Example 2:… Read More »Find the Intersection of Two Arrays in Python

Rotate an Array K Times in Python

The challenge Given an array, rotate the array to the right by k steps, where k is non-negative. Example 1: Input: nums = [1,2,3,4,5,6,7], k = 3 Output: [5,6,7,1,2,3,4]… Read More »Rotate an Array K Times in Python

Python Splices reimplemented in Java

Python has a fantastic feature called slices. It allows you to work with a list, set or string by it’s index items. E.g.: You can… Read More »Python Splices reimplemented in Java

Solving Two Sum in Python

The challenge Given an array of integers, return indices of the two numbers such that they add up to a specific target. You may assume that each… Read More »Solving Two Sum in Python

Get the Next Small Integer in Python

The challenge Write a function: def solution(A) that, given an array A of N integers, returns the smallest positive integer (greater than 0) that does… Read More »Get the Next Small Integer in Python

HashMaps (aka: Dictionaries) in Python

Introduction Java has a built-in called HashMap. It allows you to store and very quickly retrieve key value pairs. In Python, this is called a… Read More »HashMaps (aka: Dictionaries) in Python

Palindrome Partitioning in Python

The problem Given a string s, partition s such that every substring of the partition is a palindrome. Return all possible palindrome partitioning of s. Example: Input: “aab” Output: [… Read More »Palindrome Partitioning in Python

Best Time to Buy and Sell Stock with Python

The problem Say you have an array prices for which the ith element is the price of a given stock on day i. Design an algorithm to find the maximum… Read More »Best Time to Buy and Sell Stock with Python

Self Dividing Numbers using Python

Introduction A self-dividing number is a number that is divisible by every digit it contains. For example, 128 is a self-dividing number because 128 % 1 == 0, 128… Read More »Self Dividing Numbers using Python