This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /*Write a function to find the longest common prefix string amongst an array of strings. | |
| If there is no common prefix, return an empty string "". | |
| Example 1: | |
| Input: strs = ["flower","flow","flight"] | |
| Output: "fl" | |
| Example 2: | |
| Input: strs = ["dog","racecar","car"] | |
| Output: "" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /*Imagine you are a teacher. At the end of the school year, you need to calculate the average marks of your students. | |
| The marks of the students are passed as an array of strings. | |
| Each student's details are provided in a string in the following format: | |
| ‹student><mark 1><mark 2><mark N> | |
| Return a string in the following format (without white-spaces): ‹student A>-<average mark>;<student B>-‹average mark>; | |
| Take the following into account: | |
| • Any kind of separator can be used in the string. | |
| • The mark is an integer from 1-10. If the mark is out of that range, discard it, | |
| and don't use it in the average calculation. | |
| Don't forget to think through any corner cases. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /*Write a function that takes the binary representation of | |
| an unsigned integer and returns the number of '1' bits it has (also known as the Hamming weight). | |
| Note: | |
| Note that in some languages, such as Java, there is no unsigned integer type. In this case, the input will be given as a signed integer type. | |
| It should not affect your implementation, as the integer's internal binary representation is the same, whether it is signed or unsigned. | |
| In Java, the compiler represents the signed integers using 2's complement notation. Therefore, in Example 3, the input represents the signed integer. -3. | |
| Example 1: | |
| Input: n = 00000000000000000000000000001011 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /*Given two arrays arr1 and arr2, the elements of arr2 are distinct, and all elements in arr2 are also in arr1. | |
| Sort the elements of arr1 such that the relative ordering of items in arr1 are the same as in arr2. | |
| Elements that do not appear in arr2 should be placed at the end of arr1 in ascending order. | |
| Example 1: | |
| Input: arr1 = [2,3,1,3,2,4,6,7,9,2,19], arr2 = [2,1,4,3,9,6] | |
| Output: [2,2,2,1,4,3,3,9,6,7,19] | |
| Example 2: | |
| Input: arr1 = [28,6,22,8,44,17], arr2 = [22,28,8,6] | |
| Output: [22,28,8,6,17,44]*/ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import java.util.*; | |
| public class Main { | |
| public static void main(String[] args) { | |
| String input1 = "aaaaaaaaaabbbbbbccccccdddddeeeee"; | |
| String input2 = "aaaaaaaaaaaaaaaabbbbbbbbbbb"; | |
| int count = countMatchingCharacter(input1, input2); | |
| System.out.println(count); | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public class Main { | |
| public static void main(String[] args) { | |
| int num = 10; | |
| for (int i = 0; i < num; i++) { | |
| if (isPrime(i)) { | |
| System.out.println(i); | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public class Main { | |
| public static void main(String[] args) { | |
| int fibonacciLength = 15; | |
| for (int i = 0; i < fibonacciLength; i++) { | |
| System.out.print(findFibonacci(i) + " "); | |
| } | |
| } | |
| public static int findFibonacci(int input) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /*You are given a large integer represented as an integer array digits, where each digits[i] is the ith digit of the integer. | |
| The digits are ordered from most significant to least significant in left-to-right order. | |
| The large integer does not contain any leading 0's. | |
| Increment the large integer by one and return the resulting array of digits. | |
| Example 1: | |
| Input: digits = [1,2,3] | |
| Output: [1,2,4] | |
| Explanation: The array represents the integer 123. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import java.util.HashMap; | |
| import java.util.Map; | |
| public class Main { | |
| public static void main(String[] args) { | |
| String input = "abcdabc"; // Output = a2 b2 c2 d1 | |
| Map<Character, Integer> count = findCount(input); | |
| System.out.println(count); | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import java.util.Arrays; | |
| import java.util.List; | |
| import java.util.Map; | |
| import java.util.stream.Collectors; | |
| import java.util.stream.IntStream; | |
| public class Main { | |
| public static void main(String[] args) { | |
| List<Integer> integerList = Arrays.asList(1, 3, 90, 99, 50, 65, 30, 84); |
NewerOlder