Found 1862 Articles for Data Structure

Print Words with Prime length from a Sentence

Shubham Vora
Updated on 27-Oct-2023 15:24:33

189 Views

In this problem, we need to show all words of the string having the prime length. The logical part of the problem is getting the words from the string and checking whether its length is prime. We can check whether the length of the number is divisible by any number to ensure whether it is a prime number. Also, we will use the sieve of Eratosthenes and the wheel factorization algorithm to check whether the word length is a prime number. Problem statement − We have given a string alpha, and we need to print all words of ... Read More

Minimize operations to make String palindrome by incrementing prefix by 1

Shubham Vora
Updated on 23-Oct-2023 16:10:04

106 Views

In this problem, we will count the number of operations required by increasing the prefix characters of the given string. We will use character difference to count the minimum number of operations required to make string palindromic. Problem Statement We have given a string nums containing the numeric digits. We need to count a minimum number of operations required to convert a string into the palindrome. In one operation, we can select any prefix of the string and increment all prefix characters by 1. Sample Example Input nums = "22434" Output 2 Explanation ... Read More

Maximum number of Strings with Common Prefix of length K

Shubham Vora
Updated on 31-Aug-2023 18:22:33

102 Views

In this problem, we need to count the maximum string having common prefix of length K. We can take prefix of length K from all strings and count maximum number of similar prefix using the map data structure. Also, we can use the Trie data structure to solve the problem. Problem statement - We have given an strs[] array containing multiple strings. We need to count the maximum number of strings containing a common prefix of length K. Sample Example Input strs = {"tutorialspoint", "tut", "abcd", "tumn", "tutorial", "PQR", "ttus", "tuto"}; K = 3; Output ... Read More

Maximize value of Palindrome by rearranging characters of a Substring

Shubham Vora
Updated on 31-Aug-2023 18:18:39

111 Views

In this problem, we need to find the maximum palindromic string by rearranging the characters of any substring of the given string. We will use bitmasking to solve the largest palindromic substring. If any substring has bitmasking 0, it contains all characters even a number of times. So, we can generate a palindromic string using the characters of that substring, and we need to find the maximum palindromic string among them. Problem statement - We have given a string containing the N numeric characters. We need to find the maximum palindromic string by rearranging the characters of any ... Read More

Maximize sum by picking Array element to left of each ‘1’ of a Binary String

Shubham Vora
Updated on 23-Oct-2023 15:03:43

67 Views

In this problem, we will find the maximum sum of array elements by picking up unselected elements at the left from the current 1's index. We can use the vector list and sort() method to solve the problem or priority queue. The priority queue inserts the element in the sorted order. Problem Statement We have given a binary string alpha and arr[] of the same length. We need to pick all '1' of alpha one by one and take the maximum element which is not picked from the subarray of arr[] formed using 0 to p elements. Here, ... Read More

Make all Strings palindrome by swapping characters from adjacent Strings

Shubham Vora
Updated on 23-Oct-2023 14:54:49

385 Views

In this problem, we will make all strings of the given array palindromic by swapping the characters of the adjacent string. To solve the problem, we will try to make the character the same at p and str_len - p - 1 index in all strings, and it is only possible if overall characters at pth index and (str_len - p - 1) index is same. Problem statement - We have given an arr containing multiple strings of the same length equal to N. We need to count the minimum number of operations required to make all strings of ... Read More

Find Strings formed by replacing prefixes of given String with given characters

Shubham Vora
Updated on 20-Oct-2023 14:45:29

74 Views

In this problem, we will form a triangle from the given string. The triangle will contain the rows equal to the string length - 1, and in each row, we replace the starting characters equal to the row number with '.' Character. We can use the loop to form each row of the string or string constructor and substr() method. Problem statement - We have given a string alpha. We need to print the string in the triangle pattern. We need to start the triangle with the alpha string and replace the first character of the previous string ... Read More

Count Substrings with even frequency of each character and one exception

Shubham Vora
Updated on 16-Oct-2023 17:27:46

135 Views

In this problem, we will count the number of substrings of the given string containing all characters with even frequency or any single character with odd frequency. We will use the bitmasking technique to solve the problem. In bitmasking, each bit of the binary string represents the character. Problem Statement We have given a string alpha of length N. It is also given that 'a'

Count of triplets in Binary String such that Bitwise AND of S[i], S[j] and S[j], S[k] are same

Prabhdeep Singh
Updated on 31-Aug-2023 12:06:32

71 Views

A binary string is a type of string which contains only binary characters that are '0' and '1'. We are given a binary string and have to find the triplets that fulfill the condition that the bitwise 'AND' of the first two characters is equal to the bitwise 'AND' of the last two characters. Mathematically: For 0

Maximum distance between Peaks in the given Linked List

Prabhdeep Singh
Updated on 31-Aug-2023 12:05:11

79 Views

A linked list is a linear data structure that stores the data in the nodes and each node contains the address of the next node to make the connection. A peak or the peak node is the node that is not present at the first or the last place and has a value strictly greater than both of the neighbors. We have to find the maximum distance between two consecutive peaks as there could be more than one peak available. Sample Examples Input Given Linked list: 1 -> 2 -> 3 -> 2 -> 7 -> 1 ... Read More

Advertisements