Problem Write a C++ function that takes two strings of the same length as input and return true if the strings are anagrams otherwise returns false. Two strings are anagrams if they are permutations of each other ignoring spaces and capitalization. For example "CAT" and "ACT" are anagrams. Assume the input strings have small letter

Merge sort c++ string Given a character string in small letter case. Write a C++ function to sort the string using Merge Sort Algorithm. Merge sort c++ implementation Merge sort is a popular sorting algorithm that runs in O(nlogn). It uses divide and concur technique so it keeps dividing the input array into two halves

Problem Given a square two dimensional integer array of size (n). Both rows and columns are sorted in ascending order. Give an algorithm to search for a particular element in the array in O(Log(n)) time complexity. Assume the array has no duplicates. Solution This problem is a follow up from the previous post. Modified binary

Problem Given a square two dimensional integer array of size (n). Both rows and columns are sorted in ascending order. Write an efficient code to search for a particular element in the array. Assume the array has no duplicates. Solution A brute force solution is to loop through the entire array until we find the

Problem Given an amount of money in US currency. Give an algorithm to make change of the given amount using the smallest possible number of coins. Recall that US coins are Dollars (100 cents), Quarters (25 cents), Dimes (10 cents), Nickels (5 cents) and Pennies (1 cent) Solution A greedy approach to solve this problem

Reverse linked list data structure Given a singly linked list. Write a function to reverse the linked list recursively Reverse linked list algorithm The linked list can be viewed as the concatenation of the first node and the rest of the nodes. Taking this into account we can recursively reverse the rest of the nodes

Reverse linked list data structure Given a singly linked list. Write a function that reverses the linked list. Provide explanation and logic. Reverse linked list solution An iterative solution is to use two pointers. The first pointer points to the current node and the other pointer points to the next node. You loop through the

Circular linked list data structure This is a typical interview question. Given a singly linked list. Write a function that detects if the linked list is circular (has a loop) which means the last node points to another node in the list Circular linked list algorithm Explanation: There are several ways to solve this problem.

Get nth node linked list problem Given a singly linked list. Write a function that returns the nth node from the end of the list. How to find nth node in linked list Let (n) be the position (from the end of the list) of the node that we are trying to find Count the

Given a sorted array of (n) integers that has been rotated an unknown number of times. Give a log(n) algorithm that finds an element in the array. Assume the array has no duplicates.