Home Tags Posts tagged with "Set"
Tag:

Set

  • Strings

    [Hackerrank] – Two Strings Solution

    by nikoo28
    3 minutes read

    Question: Given two strings, determine if they share a common sub-string. 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 sub-string or not. If you can find a common sub-string, output “YES”, else output “NO”. Note that you don’t have to find out what is the common sub-string. Another important aspect of this problem is that the sub-string can be as small as 1 character. A…

    0 FacebookTwitterLinkedinWhatsappEmail
  • Arrays

    [Hackerrank] – Between Two Sets Solution

    by nikoo28
    5 minutes read

    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…

    1 FacebookTwitterLinkedinWhatsappEmail
  • Arrays

    Array Nesting

    by nikoo28
    4 minutes read

    Question: Given a zero-indexed array ‘A’ of length ‘N’ which contains all integers from 0 to N-1. 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,…

    0 FacebookTwitterLinkedinWhatsappEmail
  • 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…

    0 FacebookTwitterLinkedinWhatsappEmail
  • 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…

    0 FacebookTwitterLinkedinWhatsappEmail
  • Question: Given two strings, determine if they share a common sub-string. If they have a common sub-string, 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 sub-string “algo” is common between both the sub-strings and therefore the answer is “YES“. Let us try to take one more test case. String 1 = “hello” String 2 = “world”The…

    0 FacebookTwitterLinkedinWhatsappEmail

This website uses cookies to improve your experience. We'll assume you're ok with this, but you can opt-out if you wish. Accept Read More