Plus one

Here is the link to the problem: Plus one. Problem Statement: You are given a large integer represented as an integer array digits, where each digits[i] is the ith digit of the integer. The digits are ordered from most significant to least significant in left-to-right order. The large integer does not contain any leading 0’s. Increment the large integer by one and return the resulting array of digits. Examples: Example 1:...

July 13, 2024

Search Insert Position

Here is the link to the problem: Search Insert Position Problem Statement: Given a sorted array of distinct integers and a target value, return the index if the target is found. If not, return the index where it would be if it were inserted in order. You must write an algorithm with O(log n) runtime complexity. Examples: Example 1: Input: nums = [1,3,5,6], target = 5 Output: 2 Example 2:...

July 12, 2024

Index of First Occurennce in String

Here is the link to the problem: Index of First Occurrence in String Problem Statement: Given two strings needle and haystack, return the index of the first occurrence of needle in haystack, or -1 if needle is not part of haystack. Examples: Example 1: Input: haystack = “sadbutsad”, needle = “sad” Output: 0 Explanation: “sad” occurs at index 0 and 6. The first occurrence is at index 0, so we return 0....

July 11, 2024

Remove duplicates from Sorted Array

Here is the link to the problem: Remove Duplicates from sorted Array. Problem Statement: Given an integer array nums sorted in non-decreasing order, remove the duplicates in-place such that each unique element appears only once. The relative order of the elements should be kept the same. Then return the number of unique elements in nums. Consider the number of unique elements of nums to be k, to get accepted, you need to do the following things:...

July 8, 2024

Merge Two Sorted List: With and without Linked list

Here is the link to the problem: Merge Two Sorted List. Problem Statement: You are given the heads of two sorted linked lists list1 and list2. Merge the two lists into one sorted list. The list should be made by splicing together the nodes of the first two lists. Return the head of the merged linked list. Examples: Example 1: Input: list1 = [1,2,4], list2 = [1,3,4] Output: [1,1,2,3,4,4] Example 2:...

July 7, 2024

Valid Parentheses Solution: Me vs Neetcode

Here is the link to the problem: Valid Parentheses. Problem Statement: Given a string s containing just the characters ‘(’, ‘)’, ‘{’, ‘}’, ‘[’ and ‘]’, determine if the input string is valid. An input string is valid if: Open brackets must be closed by the same type of brackets. Open brackets must be closed in the correct order. Every close bracket has a corresponding open bracket of the same type....

July 5, 2024

3Sum Closest Solution: Me vs ChatGPT

Here is the link to the problem: 3Sum Closest. Problem Statement: Given an integer array nums of length n and an integer target, find three integers in nums such that the sum is closest to target. Return the sum of the three integers. You may assume that each input would have exactly one solution. Examples: Example 1: Input: nums = [-1,0,1,2,-1,-4] Target: 1 Output: 2 Explanation: The sum that is closest to the target is 2....

July 4, 2024

Solution to 3sum problem and its edge cases

Here is the link to the problem: Three Sum. Problem Statement: Given an integer array nums, return all the triplets [nums[i], nums[j], nums[k]] such that i != j, i != k, and j != k, and nums[i] + nums[j] + nums[k] == 0. Notice that the solution set must not contain duplicate triplets. Examples: Example 1: Input: nums = [-1,0,1,2,-1,-4] Output: [[-1,-1,2],[-1,0,1]] Explanation: nums[0] + nums[1] + nums[2] = (-1) + 0 + 1 = 0....

July 3, 2024

Three ways to solve the 2-sum problem

Here is the link to the problem: Two Sum. Problem Statement: Given an array of integers nums and an integer target, return indices of the two numbers such that they add up to target. You may assume that each input would have exactly one solution, and you may not use the same element twice. You can return the answer in any order. Examples: Example 1: Input: nums = [2,7,11,15], target = 9...

June 23, 2024

Casual/Informal Nepali Language Lesson 1

Often times when foreigners try to learn Nepali, they get a very formal Nepali language written in text books or websites. My goal here is to teach Nepali in a way that is spoken everyday. As someone who was born in Nepal and lived there for over 25 years, I can be the best source to learn the everyday language. Hey, how are you? -> K chha? How’s it going? -> Kasto chaldai chha?...

May 13, 2024