Must Do DSA Topics day 24
Strings
Array of Strings in C++ (3 Different Ways to Create) : In C++, a string is usually just an array of (or a reference/points to) characters that ends with the NULL character β\0β. A string is a 1-dimensional array of characters and an array of strings is a 2-dimensional array of characters.
Learn more : http://bit.ly/3O7ZY74
Strings in C : String in C programming is a sequence of characters terminated with a null character β\0β. Strings are defined as an array of characters. The difference between a character array and a string is the string is terminated with a unique character β\0β.
Learn more : http://bit.ly/3URZJPE
Storage for Strings in C : In C, a string can be referred to either using a character pointer or as a character array.
Learn more : http://bit.ly/3TAm42X
Strings
Array of Strings in C++ (3 Different Ways to Create) : In C++, a string is usually just an array of (or a reference/points to) characters that ends with the NULL character β\0β. A string is a 1-dimensional array of characters and an array of strings is a 2-dimensional array of characters.
Learn more : http://bit.ly/3O7ZY74
Strings in C : String in C programming is a sequence of characters terminated with a null character β\0β. Strings are defined as an array of characters. The difference between a character array and a string is the string is terminated with a unique character β\0β.
Learn more : http://bit.ly/3URZJPE
Storage for Strings in C : In C, a string can be referred to either using a character pointer or as a character array.
Learn more : http://bit.ly/3TAm42X
Problem Of The Day
"Longest Perfect Piece"
Solve the problem to win points
Given an array arr[] of N Numbers. A Perfect Piece is defined as a subarray such that the difference between the minimum and the maximum value in that range is at most 1. Find the Maximal Length Perfect Piece.
Example :
Input:
N = 4
arr[] = {8, 8, 8, 8}
Output:
4
Explanation:
The longest subarray is [1, 4]
where maximum=8 and minimum = 8 and
difference is 0, which is less than 1.
Its length is 4.
Your Task:
You don't need to read input or print anything. Your task is to complete the function longestPerfectPiece() which takes an Integer N and an array arr[] of length N as input and returns the maximal length Perfect Piece.
Expected Time Complexity: O(N*logN)
Expected Auxiliary Space: O(N)
Solve the problem and submit your answers here: https://practice.geeksforgeeks.org/problems/close-to-perfection1525/1
"Longest Perfect Piece"
Solve the problem to win points
Given an array arr[] of N Numbers. A Perfect Piece is defined as a subarray such that the difference between the minimum and the maximum value in that range is at most 1. Find the Maximal Length Perfect Piece.
Example :
Input:
N = 4
arr[] = {8, 8, 8, 8}
Output:
4
Explanation:
The longest subarray is [1, 4]
where maximum=8 and minimum = 8 and
difference is 0, which is less than 1.
Its length is 4.
Your Task:
You don't need to read input or print anything. Your task is to complete the function longestPerfectPiece() which takes an Integer N and an array arr[] of length N as input and returns the maximal length Perfect Piece.
Expected Time Complexity: O(N*logN)
Expected Auxiliary Space: O(N)
Solve the problem and submit your answers here: https://practice.geeksforgeeks.org/problems/close-to-perfection1525/1
www.geeksforgeeks.org
Longest Perfect Piece | Practice | GeeksforGeeks
Given an array arr[] of N Numbers. A Perfect Piece is defined as a subarray such that the difference between the minimum and the maximum value in that range is at most 1. Find the Maximal Length Perfect Piece.
Example 1:
Input:
N = 4
arr[] = {
Example 1:
Input:
N = 4
arr[] = {
Must Do DSA Topics day 25
Strings
sprintf() in C : sprintf stands for βString printβ. Instead of printing on console, it store output on char buffer which are specified in sprintf.
Learn more : http://bit.ly/3UWNe5p
Program to find second most frequent character : Given a string, find the second most frequent character in it. Expected time complexity is O(n) where n is the length of the input string.
Learn more : http://bit.ly/3UzuJ7d
C Program to Sort an array of names or strings : Given an array of strings in which all characters are of the same case, write a C function to sort them alphabetically. The idea is to use qsort() in C and write a comparison function that uses strcmp() to compare two strings.
Learn more : http://bit.ly/3Ewcdan
Strings
sprintf() in C : sprintf stands for βString printβ. Instead of printing on console, it store output on char buffer which are specified in sprintf.
Learn more : http://bit.ly/3UWNe5p
Program to find second most frequent character : Given a string, find the second most frequent character in it. Expected time complexity is O(n) where n is the length of the input string.
Learn more : http://bit.ly/3UzuJ7d
C Program to Sort an array of names or strings : Given an array of strings in which all characters are of the same case, write a C function to sort them alphabetically. The idea is to use qsort() in C and write a comparison function that uses strcmp() to compare two strings.
Learn more : http://bit.ly/3Ewcdan
Problem Of The Day
"Sum of Beauty of All Substrings"
Solve the problem to win points
Given a string S, return the sum of beauty of all its substrings.
The beauty of a string is defined as the difference in frequencies between the most frequent and least frequent characters.
For example, the beauty of string "aaac" is 3 - 1 = 2.
Example :
Input:
S = "aaac"
Output:
3
Explanation: The substrings with non - zero beauty are ["aaac","aac"] where beauty of "aaac" is 2 and beauty of "aac" is 1.
Your Task:
You don't need to read input or print anything. Your task is to complete the function beautySum() which takes string S as input paramters and returns the sum of beauty of all its substrings.
Expected Time Complexity: O(|S|2)
Expected Auxiliary Space: O(1)
Solve the problem and submit your answers here: https://practice.geeksforgeeks.org/problems/sum-of-beauty-of-all-substrings-1662962118/1
"Sum of Beauty of All Substrings"
Solve the problem to win points
Given a string S, return the sum of beauty of all its substrings.
The beauty of a string is defined as the difference in frequencies between the most frequent and least frequent characters.
For example, the beauty of string "aaac" is 3 - 1 = 2.
Example :
Input:
S = "aaac"
Output:
3
Explanation: The substrings with non - zero beauty are ["aaac","aac"] where beauty of "aaac" is 2 and beauty of "aac" is 1.
Your Task:
You don't need to read input or print anything. Your task is to complete the function beautySum() which takes string S as input paramters and returns the sum of beauty of all its substrings.
Expected Time Complexity: O(|S|2)
Expected Auxiliary Space: O(1)
Solve the problem and submit your answers here: https://practice.geeksforgeeks.org/problems/sum-of-beauty-of-all-substrings-1662962118/1
practice.geeksforgeeks.org
Sum of Beauty of All Substrings | Practice | GeeksforGeeks
Given a string S, return the sum of beauty of all its substrings.
The beauty of a string is defined as the difference in frequencies between the most frequent and least frequent characters.
For example, the beauty of string "aaac&quo
The beauty of a string is defined as the difference in frequencies between the most frequent and least frequent characters.
For example, the beauty of string "aaac&quo
Must Do DSA Topics day 26
Strings
String class in Java : String is a sequence of characters. In java, objects of String are immutable which means a constant and cannot be changed once created.
Learn More : http://bit.ly/3hLbMjw
String in Switch Case in Java : The switch statement is a multi-way branch statement. It provides an easy way to dispatch execution to different parts of code based on the value of the expression. Basically, the expression can be a byte, short, char, and int primitive data types. Beginning with JDK7, it also works with enumerated types ( Enums in java), the String class, and Wrapper classes.
Learn More : http://bit.ly/3UZu92j
Java program to swap first and last characters of words in a sentence : Write a Java Program to Swap first and last character of words in a Sentence.
Examples:
Input : geeks for geeks
Output :seekg rof seekg
Learn More : http://bit.ly/3g7VoZT
Strings
String class in Java : String is a sequence of characters. In java, objects of String are immutable which means a constant and cannot be changed once created.
Learn More : http://bit.ly/3hLbMjw
String in Switch Case in Java : The switch statement is a multi-way branch statement. It provides an easy way to dispatch execution to different parts of code based on the value of the expression. Basically, the expression can be a byte, short, char, and int primitive data types. Beginning with JDK7, it also works with enumerated types ( Enums in java), the String class, and Wrapper classes.
Learn More : http://bit.ly/3UZu92j
Java program to swap first and last characters of words in a sentence : Write a Java Program to Swap first and last character of words in a Sentence.
Examples:
Input : geeks for geeks
Output :seekg rof seekg
Learn More : http://bit.ly/3g7VoZT
Must Do DSA Topics day 27
Linked Lists
A linked list is a linear data structure, in which the elements are not stored at contiguous memory locations.
What is Linked List : Like arrays, Linked List is a linear data structure. Unlike arrays, linked list elements are not stored at a contiguous location; the elements are linked using pointers. They include a series of connected nodes. Here, each node stores the data and the address of the next node.
Learn more : http://bit.ly/3TGDdrK
Linked List vs Array : Major differences in linked lists and arrays are size, memory allocation, memory efficiency, execution time, insertion and dependency.
Learn more : http://bit.ly/3Gl7UQs
Insertion in Linked List : We have introduced Linked Lists in the previous post. We also created a simple linked list with 3 nodes and discussed linked list traversal.
All programs discussed in this post consider the following representations of the linked list.
Learn more : http://bit.ly/3Gl80HO
Linked Lists
A linked list is a linear data structure, in which the elements are not stored at contiguous memory locations.
What is Linked List : Like arrays, Linked List is a linear data structure. Unlike arrays, linked list elements are not stored at a contiguous location; the elements are linked using pointers. They include a series of connected nodes. Here, each node stores the data and the address of the next node.
Learn more : http://bit.ly/3TGDdrK
Linked List vs Array : Major differences in linked lists and arrays are size, memory allocation, memory efficiency, execution time, insertion and dependency.
Learn more : http://bit.ly/3Gl7UQs
Insertion in Linked List : We have introduced Linked Lists in the previous post. We also created a simple linked list with 3 nodes and discussed linked list traversal.
All programs discussed in this post consider the following representations of the linked list.
Learn more : http://bit.ly/3Gl80HO
Problem Of The Day
"Count of Subarrays"
Solve the problem to win points
Given an array of N positive integers Arr1, Arr2 ............ Arrn. The value of each contiguous subarray of given array is the maximum element present in that subarray. The task is to return the number of subarrays having value strictly greater than K.
Example:
Input:
N = 3, K = 2
Arr[] = {3, 2, 1}
Output: 3
Explanation: The subarrays having value
strictly greater than K are: [3], [3, 2]
and [3, 2, 1]. Thus there are 3 such
subarrays.
Your Task:
Complete the function countSubarray() which takes an array arr, two integers n, k, as input parameters and returns an integer denoting the answer. You don't to print answer or take inputs.
Expected Time Complexity: O(N)
Expected Auxiliary Space: O(1)
Solve the problem and submit your answers here: https://practice.geeksforgeeks.org/problems/count-of-subarrays5922/1
"Count of Subarrays"
Solve the problem to win points
Given an array of N positive integers Arr1, Arr2 ............ Arrn. The value of each contiguous subarray of given array is the maximum element present in that subarray. The task is to return the number of subarrays having value strictly greater than K.
Example:
Input:
N = 3, K = 2
Arr[] = {3, 2, 1}
Output: 3
Explanation: The subarrays having value
strictly greater than K are: [3], [3, 2]
and [3, 2, 1]. Thus there are 3 such
subarrays.
Your Task:
Complete the function countSubarray() which takes an array arr, two integers n, k, as input parameters and returns an integer denoting the answer. You don't to print answer or take inputs.
Expected Time Complexity: O(N)
Expected Auxiliary Space: O(1)
Solve the problem and submit your answers here: https://practice.geeksforgeeks.org/problems/count-of-subarrays5922/1
practice.geeksforgeeks.org
Count of Subarrays | Practice | GeeksforGeeks
Given an array of N positive integers Arr1, Arr2 ............ Arrn. The value of each contiguous subarray of given array is the maximum element present in that subarray. The task is to return the number of subarrays having value strictly greate
Must Do DSA Topics day 28
Linked Lists
Deletion in Linked List : We have discussed Linked List Introduction and Linked List Insertion in previous posts on a singly linked list.
Let us formulate the problem statement to understand the deletion process.
Learn more : http://bit.ly/3GkLZc9
Delete a Linked List node at a given position : Given a singly linked list and a position, delete a linked list node at the given position.
Example: Input: position = 1, Linked List = 8->2->3->1->7
Output: Linked List = 8->3->1->7
Input: position = 0, Linked List = 8->2->3->1->7
Output: Linked List = 2->3->1->7
Learn more : http://bit.ly/3Xb9Ctp
Write a function to delete a Linked List : Algorithm For C/C++: Iterate through the linked list and delete all the nodes one by one. The main point here is not to access the next of the current pointer if the current pointer is deleted.
Learn more : http://bit.ly/3hOzrPU
Linked Lists
Deletion in Linked List : We have discussed Linked List Introduction and Linked List Insertion in previous posts on a singly linked list.
Let us formulate the problem statement to understand the deletion process.
Learn more : http://bit.ly/3GkLZc9
Delete a Linked List node at a given position : Given a singly linked list and a position, delete a linked list node at the given position.
Example: Input: position = 1, Linked List = 8->2->3->1->7
Output: Linked List = 8->3->1->7
Input: position = 0, Linked List = 8->2->3->1->7
Output: Linked List = 2->3->1->7
Learn more : http://bit.ly/3Xb9Ctp
Write a function to delete a Linked List : Algorithm For C/C++: Iterate through the linked list and delete all the nodes one by one. The main point here is not to access the next of the current pointer if the current pointer is deleted.
Learn more : http://bit.ly/3hOzrPU
Problem Of The Day
"Number Of Open Doors"
Solve the problem to win points
Consider a long alley with a N number of doors on one side. All the doors are closed initially. You move to and fro in the alley changing the states of the doors as follows: you open a door that is already closed and you close a door that is already opened. You start at one end go on altering the state of the doors till you reach the other end and then you come back and start altering the states of the doors again.
In the first go, you alter the states of doors numbered 1, 2, 3, , n.
In the second go, you alter the states of doors numbered 2, 4, 6
In the third go, you alter the states of doors numbered 3, 6, 9
You continue this till the Nth go in which you alter the state of the door numbered N.
You have to find the number of open doors at the end of the procedure.
Example :
Your Task:
You don't need to read input or print anything. Your task is to complete the function noOfOpenDoors() which takes an Integer N as input and returns the answer.
Expected Time Complexity: O(βN)
Expected Auxiliary Space: O(1)
Solve the problem and submit your answers here: https://practice.geeksforgeeks.org/problems/number-of-open-doors1552/1
"Number Of Open Doors"
Solve the problem to win points
Consider a long alley with a N number of doors on one side. All the doors are closed initially. You move to and fro in the alley changing the states of the doors as follows: you open a door that is already closed and you close a door that is already opened. You start at one end go on altering the state of the doors till you reach the other end and then you come back and start altering the states of the doors again.
In the first go, you alter the states of doors numbered 1, 2, 3, , n.
In the second go, you alter the states of doors numbered 2, 4, 6
In the third go, you alter the states of doors numbered 3, 6, 9
You continue this till the Nth go in which you alter the state of the door numbered N.
You have to find the number of open doors at the end of the procedure.
Example :
Input: N =
2
Output:
1
Explanation:
Initially all doors are closed. After 1st go, all doors will be opened. After 2nd go second door will be closed. So, Only 1st door will remain Open.
Your Task:
You don't need to read input or print anything. Your task is to complete the function noOfOpenDoors() which takes an Integer N as input and returns the answer.
Expected Time Complexity: O(βN)
Expected Auxiliary Space: O(1)
Solve the problem and submit your answers here: https://practice.geeksforgeeks.org/problems/number-of-open-doors1552/1
practice.geeksforgeeks.org
Number Of Open Doors | Practice | GeeksforGeeks
Consider a long alley with a N number of doors on one side. All the doors are closed initially. You move to and fro in the alley changing the states of the doors as follows: you open a door that is already closed and you close a door that is already
Problem Of The Day
"Unique partitions"
Solve the problem to win points
Given a positive integer n, generate all possible unique ways to represent n as sum of positive integers.
Note: The generated output is printed without partitions. Each partition must be in decreasing order. Printing of all the partitions is done in reverse sorted order.
Example :
Input: n = 3
Output: 3 2 1 1 1 1
Explanation: For n = 3,
{3}, {2, 1} and {1, 1, 1}.
Your Task:
You don't need to read or print anything. Your task is to complete the function UniquePartitions() which takes n as input parameter and returns a list of all possible combinations in lexicographically decreasing order.
Expected Time Complexity: O(2^n)
Expected Space Complexity: O(n)
Solve the problem and submit your answers here: https://practice.geeksforgeeks.org/problems/unique-partitions1041/1
"Unique partitions"
Solve the problem to win points
Given a positive integer n, generate all possible unique ways to represent n as sum of positive integers.
Note: The generated output is printed without partitions. Each partition must be in decreasing order. Printing of all the partitions is done in reverse sorted order.
Example :
Input: n = 3
Output: 3 2 1 1 1 1
Explanation: For n = 3,
{3}, {2, 1} and {1, 1, 1}.
Your Task:
You don't need to read or print anything. Your task is to complete the function UniquePartitions() which takes n as input parameter and returns a list of all possible combinations in lexicographically decreasing order.
Expected Time Complexity: O(2^n)
Expected Space Complexity: O(n)
Solve the problem and submit your answers here: https://practice.geeksforgeeks.org/problems/unique-partitions1041/1
practice.geeksforgeeks.org
Unique partitions | Practice | GeeksforGeeks
Given a positive integer n, generate all possible unique ways to represent n as sum of positive integers.
Note: The generated output is printed without partitions. Each partition must be in decreasing order. Printing of all the
Note: The generated output is printed without partitions. Each partition must be in decreasing order. Printing of all the
Must Do DSA Topics day 29
Linked Lists
Find Length of a Linked List (Iterative and Recursive) : Write a function to count the number of nodes in a given singly linked list
Examples:
Input: 2->4->1->9->5->3->6
Output: 7
Learn more : http://bit.ly/3VgKHDh
Search an element in a Linked List (Iterative and Recursive) : Given a linked list and a key βXβ in, the task is to check if X is present in the linked list or not.
Examples:
Input: 14->21->11->30->10, X = 14
Output: Yes
Explanation: 14 is present in the linked list.
Learn more : http://bit.ly/3OkJmch
Write a function to get Nth node in a Linked List : Write a GetNth() function that takes a linked list and an integer index and returns the data value stored in the node at that index position.
Learn more : http://bit.ly/3gmWOzH
Linked Lists
Find Length of a Linked List (Iterative and Recursive) : Write a function to count the number of nodes in a given singly linked list
Examples:
Input: 2->4->1->9->5->3->6
Output: 7
Learn more : http://bit.ly/3VgKHDh
Search an element in a Linked List (Iterative and Recursive) : Given a linked list and a key βXβ in, the task is to check if X is present in the linked list or not.
Examples:
Input: 14->21->11->30->10, X = 14
Output: Yes
Explanation: 14 is present in the linked list.
Learn more : http://bit.ly/3OkJmch
Write a function to get Nth node in a Linked List : Write a GetNth() function that takes a linked list and an integer index and returns the data value stored in the node at that index position.
Learn more : http://bit.ly/3gmWOzH
Must Do DSA Topics day 30
Linked Lists
Program for Nth node from the end of a Linked List : Given a Linked List and a number N, write a function that returns the value at the Nth node from the end of the Linked List.
Learn more : http://bit.ly/3i13Ev6
Find the middle of a given linked list : Given a singly linked list, find the middle of the linked list. For example, if the given linked list is 1->2->3->4->5 then the output should be 3.
If there are even nodes, then there would be two middle nodes, we need to print the second middle element. For example, if the given linked list is 1->2->3->4->5->6 then the output should be 4.
Learn more : http://bit.ly/3gkj4u0
Write a function that counts the number of times a given int occurs in a Linked List : Given a singly linked list and a key, count the number of occurrences of the given key in the linked list. For example, if the given linked list is 1->2->1->2->1->3->1 and the given key is 1, then the output should be 4.
Learn more : http://bit.ly/3AsAo6P
Linked Lists
Program for Nth node from the end of a Linked List : Given a Linked List and a number N, write a function that returns the value at the Nth node from the end of the Linked List.
Learn more : http://bit.ly/3i13Ev6
Find the middle of a given linked list : Given a singly linked list, find the middle of the linked list. For example, if the given linked list is 1->2->3->4->5 then the output should be 3.
If there are even nodes, then there would be two middle nodes, we need to print the second middle element. For example, if the given linked list is 1->2->3->4->5->6 then the output should be 4.
Learn more : http://bit.ly/3gkj4u0
Write a function that counts the number of times a given int occurs in a Linked List : Given a singly linked list and a key, count the number of occurrences of the given key in the linked list. For example, if the given linked list is 1->2->1->2->1->3->1 and the given key is 1, then the output should be 4.
Learn more : http://bit.ly/3AsAo6P
Problem Of The Day
"Magic Triplets"
Solve the problem to win points
Given an array of size n, a triplet (a[i], a[j], a[k]) is called a Magic Triplet if a[i] < a[j] < a[k] and i < j < k. Count the number of magic triplets in a given array.
Example 1:
Input: arr = [3, 2, 1]
Output: 0
Explanation: There is no magic triplet.
Example 2:
Input: arr = [1, 2, 3, 4]
Output: 4
Explanation: Fours magic triplets are
(1, 2, 3), (1, 2, 4), (1, 3, 4) and
(2, 3, 4).
Your Task:
You don't need to read or print anything. Your task is to complete the function countTriplets() which takes the array nums[] as input parameter and returns the number of magic triplets in the array.
Expected Time Complexity: O(N2)
Expected Space Complexity: O(1)
Solve the problem and submit your answers here : https://practice.geeksforgeeks.org/problems/magic-triplets4003/1
"Magic Triplets"
Solve the problem to win points
Given an array of size n, a triplet (a[i], a[j], a[k]) is called a Magic Triplet if a[i] < a[j] < a[k] and i < j < k. Count the number of magic triplets in a given array.
Example 1:
Input: arr = [3, 2, 1]
Output: 0
Explanation: There is no magic triplet.
Example 2:
Input: arr = [1, 2, 3, 4]
Output: 4
Explanation: Fours magic triplets are
(1, 2, 3), (1, 2, 4), (1, 3, 4) and
(2, 3, 4).
Your Task:
You don't need to read or print anything. Your task is to complete the function countTriplets() which takes the array nums[] as input parameter and returns the number of magic triplets in the array.
Expected Time Complexity: O(N2)
Expected Space Complexity: O(1)
Solve the problem and submit your answers here : https://practice.geeksforgeeks.org/problems/magic-triplets4003/1
practice.geeksforgeeks.org
Magic Triplets | Practice | GeeksforGeeks
Given an array of size n, a triplet (a[i], a[j], a[k]) is called a Magic Triplet if a[i] < a[j] < a[k] and i < j < k. Count the number of magic triplets in a given array.
Example 1:
Input: arr = [3, 2, 1]
Output: 0
Example 1:
Input: arr = [3, 2, 1]
Output: 0
Must Do DSA Topics day 31
Linked Lists
Introduction to Circular Linked List :
What is Circular linked list?
The circular linked list is a linked list where all nodes are connected to form a circle. In a circular linked list, the first node and the last node are connected to each other which forms a circle. There is no NULL at the end.
Learn more :http://bit.ly/3EPGEZh
Traversal of Circular Linked List : In a conventional linked list, we traverse the list from the head node and stop the traversal when we reach NULL. In a circular linked list, we stop traversal when we reach the first node again.
Learn more : http://bit.ly/3gn4GRP
Split a Circular Linked List into two halves : 1) Store the mid and last pointers of the circular linked list using tortoise and hare algorithm.
2) Make the second half circular.
3) Make the first half circular.
4) Set head (or start) pointers of the two linked lists.
Learn more : http://bit.ly/3GyNBPE
Linked Lists
Introduction to Circular Linked List :
What is Circular linked list?
The circular linked list is a linked list where all nodes are connected to form a circle. In a circular linked list, the first node and the last node are connected to each other which forms a circle. There is no NULL at the end.
Learn more :http://bit.ly/3EPGEZh
Traversal of Circular Linked List : In a conventional linked list, we traverse the list from the head node and stop the traversal when we reach NULL. In a circular linked list, we stop traversal when we reach the first node again.
Learn more : http://bit.ly/3gn4GRP
Split a Circular Linked List into two halves : 1) Store the mid and last pointers of the circular linked list using tortoise and hare algorithm.
2) Make the second half circular.
3) Make the first half circular.
4) Set head (or start) pointers of the two linked lists.
Learn more : http://bit.ly/3GyNBPE
Must Do DSA Topics day 32
Stack
Introduction to Stack : It is a linear data structure that follows a particular order in which the operations are performed.
Learn more : http://bit.ly/3OvOz14
Stack in C++ STL : Stacks are a type of container adaptors with LIFO(Last In First Out) type of working, where a new element is added at one end (top) and an element is removed from that end only. Stack uses an encapsulated object of either vector or deque (by default) or list (sequential container class) as its underlying container, providing a specific set of member functions to access its elements.
Learn more : http://bit.ly/3Xn777C
Stack Class in Java : Java Collection framework provides a Stack class that models and implements a Stack data structure. The class is based on the basic principle of last-in-first-out. In addition to the basic push and pop operations, the class provides three more functions of empty, search, and peek.
Learn more : http://bit.ly/3gnDq5R
Stack
Introduction to Stack : It is a linear data structure that follows a particular order in which the operations are performed.
Learn more : http://bit.ly/3OvOz14
Stack in C++ STL : Stacks are a type of container adaptors with LIFO(Last In First Out) type of working, where a new element is added at one end (top) and an element is removed from that end only. Stack uses an encapsulated object of either vector or deque (by default) or list (sequential container class) as its underlying container, providing a specific set of member functions to access its elements.
Learn more : http://bit.ly/3Xn777C
Stack Class in Java : Java Collection framework provides a Stack class that models and implements a Stack data structure. The class is based on the basic principle of last-in-first-out. In addition to the basic push and pop operations, the class provides three more functions of empty, search, and peek.
Learn more : http://bit.ly/3gnDq5R
Problem Of The Day
"Maximum Sum LCM"
Solve the problem to win points
Given a positive number n. You need to write a program to find the maximum sum of distinct numbers such that the LCM of all these numbers is equal to n.
Example 1:
Input: n = 2
Output: 3
Explanation: The distinct numbers you can have are
just 1 and 2 and their sum is equal to 3.
Example 2:
Input: n = 5
Output: 6
Explanation: The distinct numbers you can have
are just 1 and 5 and their sum is equal to 6.
Your Task:
You dont need to read input or print anything. Complete the function maxSumLCM() which takes n as input parameter and returns the maximum sum of distinct numbers such that the LCM of all these numbers is equal to n.
Expected Time Complexity: O(sqrt(n))
Expected Auxiliary Space: O(1)
Solve the problem and submit your answers here : https://practice.geeksforgeeks.org/problems/maximum-sum-lcm3025/1
"Maximum Sum LCM"
Solve the problem to win points
Given a positive number n. You need to write a program to find the maximum sum of distinct numbers such that the LCM of all these numbers is equal to n.
Example 1:
Input: n = 2
Output: 3
Explanation: The distinct numbers you can have are
just 1 and 2 and their sum is equal to 3.
Example 2:
Input: n = 5
Output: 6
Explanation: The distinct numbers you can have
are just 1 and 5 and their sum is equal to 6.
Your Task:
You dont need to read input or print anything. Complete the function maxSumLCM() which takes n as input parameter and returns the maximum sum of distinct numbers such that the LCM of all these numbers is equal to n.
Expected Time Complexity: O(sqrt(n))
Expected Auxiliary Space: O(1)
Solve the problem and submit your answers here : https://practice.geeksforgeeks.org/problems/maximum-sum-lcm3025/1
practice.geeksforgeeks.org
Maximum Sum LCM | Practice | GeeksforGeeks
Given a positive number n. You need to write a program to find the maximum sum of distinct numbers such that the LCM of all these numbers is equal to n.
Example 1:
Input: n = 2
Output: 3
Explanation: The distinct numbers you can
Example 1:
Input: n = 2
Output: 3
Explanation: The distinct numbers you can
Must Do DSA Topics day 33
Stack
Stack in Python : A stack is a linear data structure that stores items in a Last-In/First-Out (LIFO) or First-In/Last-Out (FILO) manner. In stack, a new element is added at one end and an element is removed from that end only. The insert and delete operations are often called push and pop.
Learn more : http://bit.ly/3tUgG09
C# Stack : A Stack represents a last-in, first-out collection of objects. It is used when you need last-in, first-out access to items. It is both a generic and non-generic type of collection. The generic stack is defined in System.Collections.Generic namespace whereas non-generic stack is defined under System.
Learn more : http://bit.ly/3EVGa3H
Queue using Stacks : The problem is opposite of this post. We are given a stack data structure with push and pop operations, the task is to implement a queue using instances of stack data structure and operations on them.
Learn more : http://bit.ly/3Vo2Qiz
Stack
Stack in Python : A stack is a linear data structure that stores items in a Last-In/First-Out (LIFO) or First-In/Last-Out (FILO) manner. In stack, a new element is added at one end and an element is removed from that end only. The insert and delete operations are often called push and pop.
Learn more : http://bit.ly/3tUgG09
C# Stack : A Stack represents a last-in, first-out collection of objects. It is used when you need last-in, first-out access to items. It is both a generic and non-generic type of collection. The generic stack is defined in System.Collections.Generic namespace whereas non-generic stack is defined under System.
Learn more : http://bit.ly/3EVGa3H
Queue using Stacks : The problem is opposite of this post. We are given a stack data structure with push and pop operations, the task is to implement a queue using instances of stack data structure and operations on them.
Learn more : http://bit.ly/3Vo2Qiz
Problem Of The Day
"Longest Bitonic subsequence"
Solve the problem to win points
Given an array of positive integers. Find the maximum length of Bitonic subsequence.
A subsequence of array is called Bitonic if it is first strictly increasing, then strictly decreasing.
Example :
Input: nums = [1, 2, 5, 3, 2]
Output: 5
Explanation: The sequence {1, 2, 5} is
increasing and the sequence {3, 2} is
decreasing so merging both we will get
length 5.
Example :
Input: nums = [1, 11, 2, 10, 4, 5, 2, 1]
Output: 6
Explanation: The bitonic sequence
{1, 2, 10, 4, 2, 1} has length 6.
Your Task:
You don't need to read or print anything. Your task is to complete the function LongestBitonicSequence() which takes the array nums[] as input parameter and returns the maximum length of bitonic subsequence.
Expected Time Complexity: O(n2)
Expected Space Complexity: O(n)
Solve the problem and submit your answers here : https://practice.geeksforgeeks.org/problems/longest-bitonic-subsequence0824/1
"Longest Bitonic subsequence"
Solve the problem to win points
Given an array of positive integers. Find the maximum length of Bitonic subsequence.
A subsequence of array is called Bitonic if it is first strictly increasing, then strictly decreasing.
Example :
Input: nums = [1, 2, 5, 3, 2]
Output: 5
Explanation: The sequence {1, 2, 5} is
increasing and the sequence {3, 2} is
decreasing so merging both we will get
length 5.
Example :
Input: nums = [1, 11, 2, 10, 4, 5, 2, 1]
Output: 6
Explanation: The bitonic sequence
{1, 2, 10, 4, 2, 1} has length 6.
Your Task:
You don't need to read or print anything. Your task is to complete the function LongestBitonicSequence() which takes the array nums[] as input parameter and returns the maximum length of bitonic subsequence.
Expected Time Complexity: O(n2)
Expected Space Complexity: O(n)
Solve the problem and submit your answers here : https://practice.geeksforgeeks.org/problems/longest-bitonic-subsequence0824/1
www.geeksforgeeks.org
Longest Bitonic subsequence | Practice | GeeksforGeeks
Given an array of positive integers. Find the maximum length of Bitonic subsequence. A subsequence of array is called Bitonic if it is first strictly increasing, then strictly decreasing. Return the maximum length of bitonic subsequence.&nb
Must Do DSA Topics day 34
Stack
Design and Implement Special Stack Data Structure | Added Space Optimized Version: Design a Data Structure SpecialStack that supports all the stack operations like push(), pop(), isEmpty(), isFull() and an additional operation getMin() which should return minimum element from the SpecialStack.
Learn more: http://bit.ly/3XrfrTP
Implement two Stacks in an Array: Create a data structure twoStacks that represent two stacks. Implementation of two stacks should use only one array, i.e., both stacks should use the same array for storing elements.
Learn more: http://bit.ly/3gtyAUH
Implement Stack using Queues: Given a Queue data structure that supports standard operations like enqueue() and dequeue(). The task is to implement a Stack data structure using only instances of Queue and Queue operations allowed on the instances.
Learn more: http://bit.ly/3V2ay24
Stack
Design and Implement Special Stack Data Structure | Added Space Optimized Version: Design a Data Structure SpecialStack that supports all the stack operations like push(), pop(), isEmpty(), isFull() and an additional operation getMin() which should return minimum element from the SpecialStack.
Learn more: http://bit.ly/3XrfrTP
Implement two Stacks in an Array: Create a data structure twoStacks that represent two stacks. Implementation of two stacks should use only one array, i.e., both stacks should use the same array for storing elements.
Learn more: http://bit.ly/3gtyAUH
Implement Stack using Queues: Given a Queue data structure that supports standard operations like enqueue() and dequeue(). The task is to implement a Stack data structure using only instances of Queue and Queue operations allowed on the instances.
Learn more: http://bit.ly/3V2ay24
Problem Of The Day
βShreyansh and his bitsβ
Solve the problem to win points
Shreyansh has an integer N. He is really curious about the binary representation of integers. He sees that any given integer has a number of set bits. Now he wants to find out that how many positive integers, strictly less than N, have the same number of set bits as N.
He is a little weak in maths. Help him find the number of integers.
Note : Since N takes large values, brute force won't work.
Example 1:
Input:
N = 8
Output: 3
Explanation:
Binary representation of 8 : 1000
So the integers less than 8 with
same number of set bits are : 4, 2, 1
Hence, the result is 3.
Example 2:
Input:
N = 4
Output: 2
Explanation:
Binary representation of 4 : 100
So the integers less than 4 with
same number of set bits are : 2, 1
So, The result is 2.
Your Task:
You don't need to read input or print anything. Your task is to complete the function count() which takes the integer N as input parameters and returns the required answer.
Expected Time Complexity: O(log(n))
Expected Auxiliary Space: O(log(n)*log(n))
Solve the problem and submit your answers here :
https://practice.geeksforgeeks.org/problems/shreyansh-and-his-bits1420/1
βShreyansh and his bitsβ
Solve the problem to win points
Shreyansh has an integer N. He is really curious about the binary representation of integers. He sees that any given integer has a number of set bits. Now he wants to find out that how many positive integers, strictly less than N, have the same number of set bits as N.
He is a little weak in maths. Help him find the number of integers.
Note : Since N takes large values, brute force won't work.
Example 1:
Input:
N = 8
Output: 3
Explanation:
Binary representation of 8 : 1000
So the integers less than 8 with
same number of set bits are : 4, 2, 1
Hence, the result is 3.
Example 2:
Input:
N = 4
Output: 2
Explanation:
Binary representation of 4 : 100
So the integers less than 4 with
same number of set bits are : 2, 1
So, The result is 2.
Your Task:
You don't need to read input or print anything. Your task is to complete the function count() which takes the integer N as input parameters and returns the required answer.
Expected Time Complexity: O(log(n))
Expected Auxiliary Space: O(log(n)*log(n))
Solve the problem and submit your answers here :
https://practice.geeksforgeeks.org/problems/shreyansh-and-his-bits1420/1
practice.geeksforgeeks.org
Shreyansh and his bits | Practice | GeeksforGeeks
Shreyansh has an integer N. He is really curious about the binary representation of integers. He sees that any given integer has a number of set bits. Now he wants to find out that how many positive integers, strictly less than N, have the same numbe