Question: Given two strings, determine if they share a common substring. Input: “a” and “art” Output: YES Problem Statement Let me try to simplify this problem statement first. You are given two strings, and you need to find out if they share a common substring or not. If you can find a common substring, output “YES”, else output “NO”. Note that you don’t have to find out what is the common substring. Another important aspect of this problem is that the substring can be as small as 1 character. A …
Set


Question: You will be given two arrays of integers and asked to determine all integers between two sets that satisfy the following two conditions:– The elements of the first array are all factors of the integer being considered– The integer being considered is a factor of all elements of the second array Input:a = { 2, 6 }b = { 24, 36 } Output:2 I really want to simplify this really confusing problem statement first. The hardest part about this problem is to understand what is it actually saying. To …

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 string which consists of lowercase or uppercase letters, find the length of the longest palindromes that can be built with those letters.Input: “abccccdd”Output: 7 In the above example, the longest palindrome in the given string is “dccaccd” whose length is 7. A palindrome consists of letters with equal partners, plus possibly a unique center (without a partner). The letter i from the left has its partner i from the right. For example in ‘abcba’, ‘aa’ and ‘bb’ are partners, and ‘c’ is a unique center. Imagine we …

Question: Given an integer N, find all the prime factors of the number. Input: N = 45 Output: 3 5 Finding prime factors of any numbers is a very important concept in number theory. One sample problem is available here in which we have to find the largest prime factor. The mathematical concept behind this problem is simple. We start with ‘2’ and keep dividing the original number to get rid of composite factors. Continue this process until the number is no longer divisible by 2. This means that at …

Question: Given two strings, determine if they share a common substring. If they have a common substring, print YES else print NO. Input:studyalgorithmsalgosOutput: YES This is one of the easy problems but can get a little tricky, if we do not understand it completely. Let us try to understand the test caseString 1 = “studyalgorithms” String 2 = “algos”The substring “algo” is common between both the substrings and therefore the answer is “YES“. Let us try to take one more test case. String 1 = “hello” String 2 = “world”The …