Splitting a linked list

Given a linked list, write code to split it into two lists each containing the  alternate (odd-even) nodes from the original. If the original list […]

Finding middle element of Linked list using one loop

Write a function which will accept a pointer to the head of the linked list and returns a pointer to the middle node of the […]

Missing and repeating number in an array

Given an unsorted array of size n with numbers ranging from 1 to n. One number from set {1, 2, 3, …, n} is missing […]

Minimum Stack: Stack returning min element in O(1) time

Stack is a LIFO(Last-In-First-Out) list of elements where Push & Pop operations takes constant time, O(1). Design a Stack such that the operation of getminimum() (function […]

Find larger of 2 elements without branching

Given two unsigned integers, find the larger (or smaller) of the two without using branching (if-else or conditional operator).

Continuous sub-array with given sum

Given an array of positive integers and a number ‘k’. Find continuous subarray whith sum of all the elements = k. For example.. Array k […]

Check if two strings are anagrams

An anagram is a word play. If letters of a word can be arranged to form another word, the two words are called anagrams. e.g […]

Remove duplicates from a string

Given a string of characters. Write code which will remove duplicate characters from the string: Input: "social.ritambhara.in" Output: "social.rtmbhn"

Merge two arrays into one

There are 2 sorted arrays of size m and m+n respectively. First array (of size m) has m elements and Second array (of size m+n) […]

Permutations of list of elements with repeated values

This question is a variation of a question which I posted earlier “Print Permutations of an Array or String“. The code which I had written […]