## Algorithm to calculate power(k,n).

Objective: Given two numbers ‘k’ and ‘n’. Write an algorithm to calculate kn. Example: k = 4, n = 5 kn = 45 = 1024 k = 2, n = 3 kn = 23 =...

Objective: Given two numbers ‘k’ and ‘n’. Write an algorithm to calculate kn. Example: k = 4, n = 5 kn = 45 = 1024 k = 2, n = 3 kn = 23 =...

Objective: Write Given two integers ‘number’ and ‘divisor’, Write an algorithm to find the remainder if ‘number’ is divided by ‘divisor’. Condition: You are not allowed to use modulo or % operator. Example: num =...

Objective: Write an algorithm to swap two numbers without using extra variable. This is fun puzzle which is asked in the interview. Approach: Example: a = 3, b = 5 a = a + b...

Objective: Write an algorithm to count the number of 1’s in the bit representation in given number. Example: Number: 6 Output: 2 ( 1 1 0) Number: 11 Output: 3 ( 1 0 1 1)...

Objective: Given a number, write and algorithm to find the right most unset bit or zero bit in it (In binary representation). This problem is similar to: Find the right most set bit of...

Objective: Given a number, write and algorithm to find the right most set bit in it (In binary representation). Example: Number : 1 Binary representation: 1 Position of right most set bit: 1 Number...

Objective: Given an array of integers, find out duplicates in it. Example: int [] a = {4, 6, 2, 1, 2, 5}; Output: Array has duplicates : 2 int a [] = {1, 6,...

Objective: Given a string, write an algorithm to find the last non repeating character in it. Example: String input = “algorithms tutorials” Output: ‘u’ String input = “aabbccdd” Output: No repeating character found. Approach:...

Objective: Given a string, write an algorithm to find the last repeating character in it. Example: String input = “horizon tutorials” Output: ‘i’ String input = “algorithms” Output: No repeating character found. Approach: Naive...

Objective: Given a string, write an algorithm to find the first non repeating character in it. Example: String input = ” tutorial horizon” Output: ‘u’ String input = “aabbccadd” Output: No non-repeating character found....

Objective: Given a string, write an algorithm to find the first repeating character in it. Example: String input = “horizon tutorials” Output: ‘o’ String input = “algorithms” Output: No repeating character found. Approach: Naive...

Objective: Given a array, write an algorithm to reverse the array. Example: int a[] = {1, 2, 3, 4, 5} Output: {5, 4, 3, 2, 1} Approach: It’s obvious that you cannot use any...

Objective: Write an algorithm to implement Stack using Linked List. If you do not know about then for starters its abstract data type in which follows the principle of LIFO (Last-In-First-Out) which means the...

In this article we will see what is doubly linked list, how it is different from other linked list and how to implement it. Earlier we have seen what is Singly Linked List and...

Earlier we have seen what is Singly Linked List and How to implement it. In a way you say that it’s an extension of singly linked list. I would suggest that if you do...

%d bloggers like this: