Found 26504 Articles for Server Side Programming

Multiply Strings in C++

Aishwarya Naglot
Updated on 11-Nov-2024 15:46:46

9K+ Views

We have given two strings consisting of integers and can have lengths up to 200. both strings do not contain any leading 0, but 0 as the number itself can be present. We have to multiply integer strings, so we need to find a solution. Let's see how we can tackle this problem in an easier way. Suppose we have two numbers as strings. We need to multiply them and return the result, also in a string. For example, if the numbers are "26" and "12", then the result will be "312". Following are various ways to ... Read More

Valid Sudoku in Python

Arnab Chakraborty
Updated on 27-Apr-2020 13:08:03

5K+ Views

Suppose we have one 9x9 Sudoku board. We have to check whether that is valid or now. Only the filled cells need to be validated according to the following rules −Each row must contain the digits from 1-9 without repetition.Each column must contain the digits from 1-9 without repetition.Each of the 9 (3x3) sub-boxes of the grid must contain the digits from 1-9 without repetition.Suppose the Sudoku grid is like −537619598686348317266284195879This is valid.To solve this, we will follow these steps −for i in range 0 to 8create some empty dictionary called row, col and block, row_cube := 3 * (i ... Read More

Find First and Last Position of Element in Sorted Array in Python

Arnab Chakraborty
Updated on 27-Apr-2020 12:59:33

1K+ Views

Suppose we have an array of integers A. This is sorted in ascending order, we have to find the starting and ending position of a given target value. When the target is not found in the array, return [-1, -1]. So if the array is like [2, 2, 2, 3, 4, 4, 4, 4, 5, 5, 6], and target is 4, then the output will be [4, 7]To solve this, we will follow these steps −Initially res := [-1, -1], set low := 0, high := length of array Awhile low < highmid := low + (high – low)/2if A[mid] ... Read More

Search in Rotated Sorted Array in Python

Arnab Chakraborty
Updated on 27-Apr-2020 12:55:30

1K+ Views

Consider we have an array sorted in ascending order, and that is rotated at some pivot unknown to you beforehand. For example, [0, 1, 2, 4, 5, 6, 7] might become [4, 5, 6, 7, 0, 1, 2]. We have given a target value to the search. If we can get it in the array, then return its index, otherwise return -1. We can assume no duplicate exists in the array. So if the array is like [4, 5, 6, 7, 0, 1, 2], then the output will be 4. as the index of this element is present at index ... Read More

Divide Two Integers in C++

Arnab Chakraborty
Updated on 27-Apr-2020 12:51:59

2K+ Views

Suppose we have two integers dividend and divisor. We have to divide two integers without using multiplication, division, and mod operator. Return the quotient after dividing the dividend by divisor. The integer division should truncate toward zero. Both of the inputs are integersSo if the given inputs are dividend = 7, divisor = -3, then output will be -2.To solve this, we will follow these steps −Taking two arguments x and y it indicates x divides yif x < -Infinity and y = 1, then return infinitya := |x|, b := |y| and ans := 0while a – b >= ... Read More

Swap Nodes in Pairs in C++

Arnab Chakraborty
Updated on 27-Apr-2020 12:39:29

850 Views

Consider we have a linked list. We have to swap every two adjacent nodes and return its head. The constraint is that we cannot modify the value of the nodes, only the node itself can be changed. So if the list is like [1, 2, 3, 4], then the resultant list will be [2, 1, 4, 3]To solve this, we will follow these steps −if head is not present, then return headfirst := head, second := next of head, dummy is one new node with value -1next of dummy := first, and prev := dummywhile second is not nulltemp := ... Read More

Generate Parentheses in Python

Arnab Chakraborty
Updated on 27-Apr-2020 12:34:31

3K+ Views

Suppose we have a value n. We have to generate all possible well-formed parentheses where n number of opening and closing parentheses are present. So if the value of n = 3, then the parentheses set will be ["()()()", "()(())", "(())()", "(()())", "((()))"]To solve this, we will follow these steps −Define method called genParenthesisRec(). This takes left, right, temp string and result array. initially result array is emptyThe function genParenthesisRec, will work like belowif left = 0 and right := 0, then insert temp into result, and returnif left > 0getParenthesisRec(left – 1, right, temp + “(”, result)if right > ... Read More

Remove Nth Node From End of List in Python

Arnab Chakraborty
Updated on 27-Apr-2020 12:27:41

693 Views

Suppose we have a linked list. We have to remove the Nth node from the end of the list, then return its head. So if the list is like [1, 2, 3, 4, 5, 6] and n = 3, then the returned list will be [1, 2, 3, 5, 6].To solve this, we will follow these steps −If there is no node after head, then return Nonefront := head, back := head, counter := 0 and fount := falsewhile counter

4Sum in C++

Akansha Kumari
Updated on 23-Jul-2025 15:44:35

611 Views

4SUM ProblemThe 4Sum is one of the problem variations in which we need to find the number of quadruplets present in the array such that their sum is equal to the given target. We are given an array of n integers called nums and a target value, and we have to find the number of index quadruplets (i, j, k, l) where i, j, k, and l are all indices in the range 0 to n - 1, such that they satisfy the condition: nums[i] + nums[j] + nums[k] + nums[l] = target Scenario 1 Inputs: arr= [-1, 0, 1, 2, ... Read More

Iswctype() function in C++ STL

Sunidhi Bansal
Updated on 30-Jan-2020 09:50:37

89 Views

In C++ standard template libraray(STL), iswctype() function is used to check if the given wide character has property specified by desc.Iswctype() is an in built function whose header file is “ctype.h”.Syntax of Iswctype() is as followsint iswctype(wint_t c, wctype_t desc); iswctype () / Checks whether whether c has the property specified by desc. /Synopsisint iswctype(wint_t c, wctype_t desc);ParametersC − To check the wide characters which are casted to the integral type wint_tDesc − It is a value which is returned by the call to wctype, which is a scalar type which is used as return type for wctype(Wide character type).Return ... Read More

Advertisements