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,…
nikoo28
nikoo28
a techsavvy guy and a design buff... I was born with the love for exploring and want to do my best to give back to the community. I also love taking photos with my phone and Canon Kiss X5 in order to capture moments in my life. It's my pleasure to have you here.


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 a binary tree, return the length of the diameter. The diameter of the binary tree is defined as the length of the longest path between any two nodes in the tree. In the above example the diameter of the binary tree is 7. Problem Statement: We can easily find out the distance between two nodes in a binary tree. In the given example, the distance between node 5 and 8 is 4. The distance between node 2 and 6 is 3, the distance between node 8…

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…

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 may or may not contain repetitions. Brute Force Method: As soon as you see the problem, the most first thought that comes to your mind would be to find all the substrings from the given string and keep a track of the longest one that…

Question: Given an array A, find the sum of maximum sum of two nonoverlapping subarrays, with lengths L and M.In other words, return the largest V for which V = (A[i] + A[i+1] …. A[i+L1]) + (A[j] + A[j+1] …. A[j+M1])Input: A = {3, 8, 1, 3, 2, 1, 8, 9, 0}; L = 3, M = 2Output: 29 The problem statement is quite clear. We need to find 2 contiguous subarrays from an array Add the elements of both these arrays The sum should be the maximum possible sum…

Question: Given a zeroindexed array ‘A’ of length ‘N’ which contains all integers from 0 to N1. Find and return the longest length of set S, where S[i] = {A[i], A[A[i]], A[A[A[i]]], …} subjected to a particular condition. Suppose the first element in S starts with the selection of element A[i] of index = i, the next element in S should be A[A[i]], and then A[A[A[i]]],.. and so on. By that analogy, we stop adding elements as soon as we get a duplicate. Input: A = {5, 4, 0, 3,…

Question: Given a set of queries and a pattern, we need to determine if some of those queries can be made from the given pattern by adding one or more lower case character. Output a boolean array where array[i] says true, if the query is possible, else false. Input: queries= {“StudyAlgorithms”, “StudyAlgorithmsTest”, “StanAlluring”, “SimulationAlteration”, “StopStayAlive”}pattern = “StAl” Output: {true, false, true, true, false} Let us try to understand the output.The pattern defined to us is St*Al* (if we see it in terms of a regex) StudyAlgorithms can be made as…