Implement strstr function in Java
Write an efficient algorithm to implement the strstr function in Java, which returns the index of the first occurrence of a string in another string.
Ace your Coding Interview
Get hired by top tech companies with our comprehensive interview preparation.
Get StartedWrite an efficient algorithm to implement the strstr function in Java, which returns the index of the first occurrence of a string in another string.
Euclid’s algorithm (or Euclidean algorithm) is a method for efficiently finding the greatest common divisor (GCD) of two numbers. The GCD of two integers, X and Y, is the largest number that divides both X and Y without leaving a remainder.
The extended Euclidean algorithm is an extension to the Euclidean algorithm, which computes, besides the greatest common divisor of integers a and b, the coefficients of Bézout’s identity, i.e., integers x and y such that ax + by = gcd(a, b).
In this post, we will see how to reverse an array in C in linear time.
Find the duplicate numbers in an integer array of size n that contains elements between 1 and n, at least one of which repeats.
Given a linked list, remove all nodes from it that match a given key.
Given a binary matrix in which the values 0 and 1 correspond to land and water, respectively, and the connected ones form exactly one island, find the perimeter of an island.
Given a string, find the length of the longest palindrome possible from its characters.
Given a positive number n, construct an integer array of length n where each index stores the count of 1’s in the binary representation of the index.
Given two strings, check if the second string can be constructed from characters of the first string, where each character of the first string can be used only once in the second string.
Given two strings, check if the second string is a subsequence of the first string.
Given the root of a binary tree, determine if the binary tree holds children-sum property. For a tree to satisfy the children-sum property, each node’s value should be equal to the sum of values at its left and right node.