Segregate positive and negative integers in linear time
Given an array of positive and negative integers, segregate them in linear time and constant space. The output should print all negative numbers followed by all positive numbers.
Ace your Coding Interview
Get hired by top tech companies with our comprehensive interview preparation.
Get StartedGiven an array of positive and negative integers, segregate them in linear time and constant space. The output should print all negative numbers followed by all positive numbers.
Merge sort is an efficient sorting algorithm that produces a stable sort, which means that if two elements have the same value, they hold the same relative position in the sorted sequence as they did in the input.
Bubble sort is a stable, in-place sorting algorithm named for smaller or larger elements “bubble” to the top of the list. Although the algorithm is simple, it is too slow and impractical for most problems even compared to insertion sort, and is not recommended for large input.
Selection sort is an unstable, in-place sorting algorithm known for its simplicity. It has performance advantages over more complicated algorithms in certain situations, particularly where the auxiliary memory is limited.
Insertion sort is a stable, in-place sorting algorithm that builds the final sorted array one item at a time. It is not the very best in terms of performance but more efficient traditionally than most other simple O(n^2) algorithms such as selection sort or bubble sort.
Sieve of Eratosthenes is an efficient algorithm that can be used in most coding competitions involving prime numbers in the range of a given number n.
Given an array of n-1 distinct integers in the range of 1 to n, find the missing number in it in linear time.
Write a program to calculate the nth Fibonacci number where n is a given positive number. Fibonacci’s sequence is characterized by the fact that every number after the first two is the sum of the two preceding ones.
This article will provide C++ implementation of a queue data structure using templates in C++. This article will make the class code generic by using C++ templates to support all data types.
In this article, we will discuss the C++ implementation of the stack data structure using classes and make code generic for all data types by using C++ templates.
Write code to evaluate a given postfix expression efficiently. For example, 82/ will evaluate to 4 (8/2), 138×+ will evaluate to 25 (1+8×3) and 545×+5/ will evaluate to 5 ((5+4×5)/5).
Given a string containing opening and closing braces, check if it represents a balanced expression or not.