Found 7401 Articles for C++

Given a sequence of words, print all anagrams together

Divya Sahni
Updated on 03-Nov-2023 14:52:20

190 Views

Anagrams − An anagram is a word or a phrase formed by rearranging the alphabets of another word or phrase, usually once. Some examples of anagrams are given below − Top - Pot Silent - Listen Post - Stop Dog - God Problem Statement Given an array of words arr[]. For the given array print all the anagrams together. Sample Example 1 Input arr[] = {“star”, “god”, “vile”, “save”, “evil”, “care”, “arts”, “race”, “dog”, “vase”} Output arts star care race dog god evil vile save vase ... Read More

Find the interval which contains the maximum number of concurrent meetings

Divya Sahni
Updated on 03-Nov-2023 14:49:01

105 Views

Given a scenario of a company where meetings are held during fixed time slots. These slots might be overlapping or distant. Thus, optimizing meeting efficiency is important in order to accommodate maximum meetings without any conflicts between schedules. In the problem given, we’ll be going through such an optimizing meeting efficiency problem. Problem Statement Given a two-dimensional array time[][] containing the start time and end time of all the meetings that are scheduled for that day. The task is to find the time interval when most of the meetings are occurring. Sample Example 1 Input: time[][] = {{1, 5}, {2, 6}, {3, 7}, {4, ... Read More

Design an efficient data structure for given operations

Divya Sahni
Updated on 03-Nov-2023 14:45:34

108 Views

In order to design efficient data structures for specific operations, the time and space complexity of the given operations for the data structure created is important. Looking into some basic operations and how they can be efficiently optimized − insert() − Inserts an element to the data structure Dynamic Arrays, Hash Tables, Binary Search Trees and Balanced Search Trees like AVL Trees or Red-Black Trees are the most efficient choice of data structures providing O(1) complexity for insertions operation. delete() − Deletes an element from the data structure Hash tables approach the deletion process in O(1) time while Binary Search Trees and Balanced Search ... Read More

Maximum level sum in N-ary Tree

Divya Sahni
Updated on 03-Nov-2023 14:39:39

141 Views

The N-ary tree is a tree data structure where each node can have a maximum of N children where N is a positive integer (N >= 0). N-ary trees are used in many applications like file systems, organizational charts and syntax trees in programming languages. Example of N-ary tree with N = 4. A / / \ \ B C D E / | \ ... Read More

Three-way partitioning of an Array without changing the relative ordering

Satvik Watts
Updated on 01-Nov-2023 12:55:18

69 Views

In this article, we will do a three-way partitioning of an array containing N integers. The approach is to use three queues. Each of these queues will be used to store the elements of one of the parts. After that, we can get the elements of each part from their respective queues without changing the relative order of the elements Problem Statement Given an array containing N integers and a range [LOW, HIGH], we need to partition the array into three parts such that − Elements less than LOW comes first Elements greater than LOW and lower than HIGH ... Read More

Sum of Array maximums after K operations by reducing max element to its half

Satvik Watts
Updated on 01-Nov-2023 12:53:00

61 Views

In this article, we will calculate the sum of the array maximums after K operations in which we reduce the maximum value of the array to its half. In the first approach, we will implement the brute force solution to this problem. In each iteration, we will use a for loop to find the maximum element in the array. We will then add this element to our answer, then we will reduce the element to its half. We will do this for K iterations as requested. Then, we will return the answer. In the second approach, we will use a ... Read More

Sort a given array which is already sorted based on the absolute value of the element

Satvik Watts
Updated on 01-Nov-2023 12:51:02

59 Views

In this article, we will sort the given array. The given array is already sorted on the basis of absolute value of the elements, we just need to sort the array based on the true values of the elements. In the first approach, we will use a sorting algorithm, like merge sort, bubble sort, insertion sort, quicksort and so on. In this example, we will use the inbuilt sort function to sort our array. In the second approach, we will use a double ended queue. We will push the positive elements in front of the double ended queue, and we ... Read More

Shortest path between two points in a Matrix with at most K obstacles

Satvik Watts
Updated on 01-Nov-2023 12:49:25

77 Views

In this article, we will find the shortest path between two points in a matrix. The matrix contains two types of cells, empty cells and cells which have obstacles. We are given an integer K, which represents that we can remove at most K obstacles to reach our destination. In the approach discussed in this article, we will do a breadth first search (BFS) on the matrix to find the shortest path. We will use a queue data structure, which will store a vector of integers. The vector will have 3 integers, the x coordinate, the y coordinate and the ... Read More

C++ Program to Find Minimum circular rotations to obtain a given numeric string by avoiding a set of strings

Satvik Watts
Updated on 01-Nov-2023 12:44:40

23 Views

In this article, we will find the minimum circular rotations that are needed to obtain a given numeric string, target, by avoiding a given set of strings. The target strings and the strings in the set of string both have a size of N. The initial string will be a string containing all zeroes and the length of the input string will also be N. In the approach discussed in this article, we will use a queue data structure and a set data structure. The queue data structure will hold the strings that we are currently at, i.e., the numeric ... Read More

Maximum count of pairs such that element at position i is included in a[i] pairs

Satvik Watts
Updated on 01-Nov-2023 12:40:29

28 Views

In this article, we will find the number of the pair of indices, such that an index i can be included in at most a[i] number of pairs. In the approach discussed in this article, we will use a priority queue data structure which will contain the elements of the array. The priority queue data structure will be a maximum heap which will allow us to get the current maximum elements of the array on log(N) time. It will also allow us to modify the elements and insert them back in, in the same amount of time. We will ... Read More

Advertisements