Published in Level Up Coding·Jul 3LeetCode 75 Level 1 — Is SubsequenceProblem Given two strings s and t, return true if s is a subsequence of t, or false otherwise. A subsequence of a string is a new string that is formed from the original string by deleting some (can be none) of the characters without disturbing the relative positions of the…Python Programming2 min read

Published in Level Up Coding·Jul 3LeetCode 75 Level 1 — Running Sum of 1D ArrayProblem Given an array nums. We define a running sum of an array as runningSum[i] = sum(nums[0]…nums[i]). Return the running sum of nums. Examples Example 1: Input: nums = [1,2,3,4] Output: [1,3,6,10] Explanation: Running sum is obtained as follows: [1, 1+2, 1+2+3, 1+2+3+4]. Example 2: Input: nums = [1,1,1,1,1] Output: [1,2,3,4,5] Explanation: Running sum…Python Programming1 min read

Published in Level Up Coding·May 2Minimum Number of Coins that must be Reversed to Achieve Alternating Sequence of Heads and TailsProblem There are N coins, each showing either heads or tails. We would like all the coins to form a sequence of alternating heads and tails. What is the minimum number of coins that must be reversed to achieve this? Given an array A consisting of N integers representing the coins…Leetcode3 min read

Published in Level Up Coding·Mar 22Merge Two Sorted Linked Lists — LeetcodeProblem Examples Example 01 Input: list1 = [1,2,4], list2 = [1,3,4] Output: [1,1,2,3,4,4] Example 02 Input: list1 = [], list2 = [] Output: [] Example 03 Input: list1 = [], list2 = [0] Output: [0] Algorithm Walk-through Initial current = dummy = Node() After executing the source code, the state of the linked lists shown…Linked Lists3 min read

Published in Level Up Coding·Mar 22Queue using Two Stacks —HackerrankProblem Implement a queue using two stacks. Then process q queries, where each query is one of the following 3 types: Enqueue element x into the end of the queue Dequeue the element at the front of the queue Print the element at the front of the queue Example Input The first line…Hackerrank3 min read

Published in Level Up Coding·Mar 18Merge Two Sorted Arrays in PythonProblem Given two sorted arrays, merge them into a sorted manner. Examples Example 01 Input: arr1 = [3, 5, 6, 10], arr2 = [1, 2, 7, 8, 11, 12] Output: arr3 = [1, 2, 3, 5, 6, 7, 8, 10, 11, 12] Example 02 Input: arr1 = [1, 3, 4, 5]…Coding Interviews3 min read

Published in Level Up Coding·Mar 15Find the Length of the Longest Substring Without Repeating Characters — LeetcodeProblem Given a string, find the length of the longest substring without repeating characters. Examples Example 1: Input: s = "abcabcbb" Output: 3 Explanation: The answer is "abc", with the length of 3. Example 2: Input: s = "bbbbb" Output: 1 Explanation: The answer is "b", with the length of 1. Example…Coding Interviews2 min read

Published in Level Up Coding·Mar 14Find Palindrome in a Sentence with Punctuation and/or Spaces in GolangProblem Palindrome: String that is read the same forwards and backwards, example: anna, racecar, bananab Definition: If you discard spaces and punctuation marks, the resulting string is a palindrome Sample 01: “never a foot too far, even.” → true Sample 02: “,,,,never a foot too far, even.” …Golang2 min read

Published in Level Up Coding·Mar 14Cell Lifecycle at a Given Time in Python and GolangProblem Consider a cell, it has the following life cycle: A cell is born at time = 0 When a cell is born, the age will be 0 Cell gives birth to another cell when the age of the cell is 2 Cell gives birth to another cell when the age…Coding3 min read

Published in Level Up Coding·Oct 3, 2021Solve How Many Steps is Required to Fill a 2 Dimensional ArrayProblem Given the array A , m rows x n columns of 0 and 1 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 1 0 0 0 0 0 0 0 0 For…Python 32 min read