Given an array of integers, find the elements that appear twice. The main challenge of this problem is to solve it without using any extra space. You need to find a way to mark the elements that are already encountered. Once such way would be to make the elements negative. This post gives you 2 different solutions a video explanation.
Leetcode


Given an array of strings, group all the anagrams together. This post explores 2 methods to solve this problem. You can create groups by sorting, or by categorizing using the frequency of characters.

You are given an array that is sorted but also rotated by an unknown number of times. Given a target value, return the index if it can be found. In this post we discuss the solution to this problem using a modified version of the binary search technique.


Given two strings str1 and str2. Write a function to determine if str1 is an anagram of str2. Example 1:str1 = “listen”, str2 = “silent”Output = True Example 2:str1 = “mississippi”, str2 = “mips”Output = False Terminology: Anagram: Two words or phrases are said to be anagrams of each other if they can be formed by reshuffling of characters in one of them. Problem Statement: In the given problem we have 2 strings as input. They may be single words or phrases. Return true if they anagrams of each other,…

You are given a string with some repeating characters and some unique characters. Find the first unique character and return its index. Example 1:Input: studyAlgorithmsOutput: 2 Example 2:Input: iLoveToCodeOutput: 0 Problem Statement: I want to simplify the problem statement first before we begin to solve it. An input string consists of some uppercase and lowercase characters which may or may not be repeated. Out of all the unique characters, you need to return the characters that occurs first in the string. In the first example studyAlgorithms, s, and t are…

You are provided with an array of integers. We need to find the subarray with the maximum sum such that all the elements are contiguous. Example:Input: [2, 5, 6, 2, 3, 1, 5, 6]Output: 7Explanation: The subarray with maximum sum is [6, 2, 3, 1, 5] Problem Statement: You are provided with an array of integers. These elements could be all positive, all negative or a combination of both. A subarray is a smaller array formed using the elements of the original array. The condition for this problem is that…

You are given 2 sorted linked lists with a head pointer. Find a way to merge these 2 lists and return a single sorted list. Try to solve the problem without using any extra space. Example 1:List 1: 1 > 2 > 4List 2: 1 > 3 > 4Output: 1 > 1 > 2 > 3 > 4 > 4 Problem statement To read about Linked Lists, refer to the post “What is a Linked List“? For our current problem statement, we are given two list heads or we refer…

Let us suppose you are given an array of integers. The special thing about this array is that all numbers are repeated twice except one. Find the single nonrepeating number. Example 1:Input: [2, 1, 1]Output: 2 Example 2:Input: [4, 5, 5, 2, 2]Output: 4 Problem statement: You are given an array of all positive integers. All the integers are repeated exactly twice except one. We need to find that number with a linear time complexity and using the minimum space possible. Brute Force Method: When tackling such problems, it is…

Let us suppose that we are given a string ‘str’. You need to find out the longest palindrome as a substring. Note that the elements of the string should be contagious. Example 1:Input: “aaebabad”Output: “bab”Note: “aba” is also a valid answer Example 2:Input: “cbeereed”Output: “eeree” Terminology: Palindrome: A palindrome is a type of string that reads the same when reading left to right and right to left. An example of a palindrome can be “level”, “racecar”, “kayak” etc. Substring: A string formed formed using the characters of the string that…