Coding Problems
How do you find the factorial of an integer?
Apply recursion to the number until it reaches one.
Explain overloading and overriding with the help of a program?
Overloading: When a class has two or more methods with the same name, they are called overloaded methods.
Code the insert sort algorithm
Write the code segment logic.
Code the bubble sort algorithm
Write the code segment logic. 1. Declare integer array 2.
How do you sum all the elements in an array?
Loop through array and add elements in the array.
How to determine if a string is palindrome?
A string is palindrome when it stays the same on the reversing characters in that string. 1. Check if the reverse string is equal to the target string.
How do you reverse an array?
1. Declare integer array predefined. 2. Loop through the half length of the array 3. Replace the number corresponding to the indexes 4.
How do you get matching elements in an integer array?
1. Declare integer array predefined. 2. Nested For loop to print matching elements.
Swap two numbers without using third variable?
1. Declare two variables 2. make b the sum of both variables 3. Subtract the sum to a 4. subtract b to a
How do you calculate the number of vowels and consonants in a string?
1. Declare vowels and consonants counter 2. Loop through the string. 3. Check if char in string is vowel else its a consonant
Find the number of occurrences of a character in a string.
1. Initialize Count and search 2. Loop through string and count the occurrence of search variable 3. Print count
Find the second largest number in an array?
1. Loop through the array 2. If i is higher than the highest store the second highest to be the highest, store highest to i
How do you reverse a string?
1. Take a string. 2. Take the length of the string 3. Loop through the characters of the string 4. Add these characters in reverse order. 5. Print the resulting string.
How do you remove all occurrences of a given character from the input string?
1. Use builtin string method
Check if the given number is prime?
1. Use if statements to check each condition separately 2. Use a for loop to check if the number is divisible to itself or 1, return false.
Find if two given strings are anagrams
Two strings are anagram if they contain a similar group of characters in a sequence. 1. Declare a boolean value to test if two strings are anagram. 2. Check if both strings are the same length. 3. If they are the same lenghth then they might be anagrams. 4. Convert both sttrings to character arrays and sort them by characters 5. check if the sorted arrays are equal. 6. If equal print if anagrams.