Significance of Lambda Function in C/C++

Dev Prakash Sharma
Updated on 05-Feb-2021 12:51:35

4K+ Views

Lambda Function − Lambda are functions is an inline function that doesn’t require any implementation outside the scope of the main program.Lambda Functions can also be used as a value by the variable to store. Lambda can be referred to as an object that can be called by the function (called functors).Whenever the compiler encounters a definition of the lambda function, it generally creates a custom object for the lambda.A lambda function has more functionality than a normal function, for example, it has a capturing method to capture the used variables. However, the captured variable is treated as the member ... Read More

Search Element in Singly Linked List using C++

Dev Prakash Sharma
Updated on 05-Feb-2021 12:50:20

569 Views

Given a singly linked list, the task is to search a particular element in the linked list. If the element is found, then print “present” otherwise “Not present”. For example, Input-1 −1→ 2→ 3→ 4→ 5→ 6Searching for ‘7’Output −Not PresentExplanation − In the given singly linked list the element ‘7’ is not present, hence we will return the output as “Not Present”.Input-2 −1→ 2→ 3→ 4→ 5Searching for ‘2’Output −PresentExplanation − Since in the given Singly linked list the element ‘2’ is present thus we will return the output as “Present”.Approach to solve this problemThere are two approaches to ... Read More

Rotate a Matrix by 90 Degrees in Anticlockwise Direction in Java

Dev Prakash Sharma
Updated on 05-Feb-2021 12:49:35

2K+ Views

Let’s suppose we have given a square matrix of N×N. The task is to rotate the matrix counterclockwise. For example, Input-1 −N = 3 matrix[ ][ ] = [    [1 2 3],    [4 5 6],    [7 8 9] ]Output −3 6 9 2 5 8 1 4 7Explanation: After rotating the matrix counterclockwise it will generate the output as, 3 6 9 2 5 8 1 4 7.Approach to solve this problemInitially the idea is to find the transpose of the given matrix and then swap each of the elements of the matrix while traversing row-wise.Take Input ... Read More

Reverse Vowels of a String in C++

Dev Prakash Sharma
Updated on 05-Feb-2021 12:49:03

2K+ Views

Given a string, the task is to reverse all the vowels present in the given string. For example, Input-1 −a = “tutor”Output −toturExplanation − Reversing the string “tutor” will generate the output as “totur.Input-2 −a = “mathematics”Output −mithametacsExplanation − Reversing the string “mathematics” will generate the output as “mithametacs”.Approach to solve this problemGiven a string, we have to reverse all the vowels present in it. There are several approaches to solve this particular problem but we have to solve this in linear time O(n).Thus, the better method to solve this problem is to use the Two-Pointer approach in which we ... Read More

Replace All 0's with 5 in a Given Number using C++

Dev Prakash Sharma
Updated on 05-Feb-2021 12:48:02

1K+ Views

Given an integer N, the task is to replace all the 0’s that appear in the number with ‘5’. However, the number with leading ‘0’ cannot be replaced with ‘5’ as it remains unchanged. For example, Input-1 −N= 1007Output −1557Explanation − The given number has 2 zeros which when replaced by ‘5’ results in the output as 1557.Input-2 −N = 00105Output −155Explanation − Since the given number starts with the leading ‘0’ which can be ignored and the output after replacing the 0 in the middle with ‘5’ results the output as 155.Approach to Solve this ProblemTo replace all the ... Read More

Remove Duplicates from Array of Prime Numbers in C++

Dev Prakash Sharma
Updated on 05-Feb-2021 12:46:48

349 Views

Let us suppose we have given an array N size which consists of all the prime numbers. The task is to find the duplicates in the given array and remove them. For example, Input-1 −N = 8 arr[ ] = { 2 ,2 ,2 ,3 ,3 ,3 ,5 ,7 }Output −2 3 5 7Explanation − In the given array of prime numbers there are some duplicates of ‘2’ and ‘3’ after removing the duplicates the output will be 2 3 5 7.Input-2 −N = 5 arr[ ] = { 3, 2, 7, 5, 5}Output −3 2 7 5Explanation − In ... Read More

Remove Comments in a String Using C++

Dev Prakash Sharma
Updated on 05-Feb-2021 12:46:09

1K+ Views

Given a C++ program as input, remove the comments from it. ‘source’ is a vector where the i-th line of the source code is the source[i]. This represents the result of splitting the source code string by the newline character . In C++, we can create two types of comments, i.e., Line Comments, Block Comments.The string ‘\’ denotes the line comment, which means the string next to it on the right will be ignored by the program.The string ‘\* and *\’ is a multiline comment representing the string starting from ‘\* till the *\’ will be ignored.The first useful comment ... Read More

Nth Catalan Number in Go Language

Dev Prakash Sharma
Updated on 05-Feb-2021 12:45:36

238 Views

Catalan Numbers are sequences of natural numbers that gives the number of BST (Binary Search Tree) possible with n Values. So, the Catalan number is a full binary tree with n+1 leaves.Some applications of Catalan Numbers are counting the pairs of nested parentheses, valid mountain ranges etc.For n = 5, C = (C(0) * C(4)) + (C(1) * C(3)) + (C(2) * C(2)) + (C(3) * C(1)) + (C(4)* C(0))Thus, we can see that Catalan numbers are in the form of a recursive relation, i.e., for the nth term, the Catalan number Cn is,             ... Read More

Majority Element in Java

Dev Prakash Sharma
Updated on 05-Feb-2021 12:43:28

1K+ Views

Let’s suppose we have given an array of integers. The task is to find the index of a particular element in the given array. For example, Input-1 −N = 8 A[ ] = { 1, 2, 4, 3, 3, 1, 1, 5}Output −1Explanation − In the given array of integers, the most appearing number is ‘1’. Thus the output is ‘1’.Input-2 −N = 6 A[ ] = {1, 5, 4, 4, 1, 1}Output −1Explanation − In the given array of integers, the most appearing number is ‘1’. Thus we can return the output ‘1’.Approach to solve this problemThe given array ... Read More

Insert Node at Beginning of Singly Linked List in C++

Dev Prakash Sharma
Updated on 05-Feb-2021 12:43:04

7K+ Views

A linked List is a linear data structure that has multiple nodes that are connected with each other. Each node consists of two fields Data Field and address of the next node.Let us assume we have given a singly linked list the task is to insert a node at the beginning of the given linked list. For example, Input-1 − 1 → 2 → 3 → 4Insert ‘5’ at the head or beginning of the given linked list.Output − 5 → 1 → 2 → 3 → 4Explanation − After inserting the node at the beginning of the linked list ... Read More

Advertisements