Found 26504 Articles for Server Side Programming

Excel Sheet Column Title in C++

Arnab Chakraborty
Updated on 10-Jun-2020 12:21:25

850 Views

Suppose we have a positive integer; we have to find its corresponding column title as appear in an Excel sheet. So [1 : A], [2 : B], [26 : Z], [27 : AA], [28 : AB] etc.So, if the input is like 28, then the output will be AB.To solve this, we will follow these steps −while n is non-zero, do −n := n - 1res := res + n mod 26 + ASCII of 'A'n := n / 26reverse the array resreturn resExample Let us see the following implementation to get a better understanding − Live Demo#include using namespace std; ... Read More

Pascal's Triangle II in C++

Arnab Chakraborty
Updated on 10-Jun-2020 12:19:06

341 Views

Suppose we have a non-negative index k where k ≤ 33, we have to find the kth index row of Pascal's triangle.So, if the input is like 3, then the output will be [1,3,3,1]To solve this, we will follow these steps −Define an array pascal of size rowIndex + 1 and fill this with 0for initialize r := 0, when r

Minimum Depth of Binary Tree in C++

Arnab Chakraborty
Updated on 10-Jun-2020 12:17:28

155 Views

Suppose we have a binary tree; we have to find the minimum depth of that tree. As we know the minimum depth is the number of nodes along the shortest path from the root node down to the nearest leaf node.So, if the input is likethen the output will be 2To solve this, we will follow these steps −Define an array aa of tree nodesinsert root at the end of aaDefine another array ak of tree nodeslevel := 0if root is null, then −return 0while size of aa is not equal to 0, do −clear the array ak(increase level by ... Read More

Same Tree in C++

Arnab Chakraborty
Updated on 10-Jun-2020 12:11:41

398 Views

Suppose we have two binary trees; we have to define a function to check whether they are the same or not. We know that the binary trees are considered the same when they are structurally identical and the nodes have the same value.So, if the input is like [1, 2, 3], [1, 2, 3], then the output will be TrueTo solve this, we will follow these steps −Define a function called isSameTree, this will take two tree nodes p and qif p is the same as NULL and q is same as NULL, then −return trueif p is the same ... Read More

Remove Duplicates from Sorted List in C++

Arnab Chakraborty
Updated on 10-Jun-2020 12:08:35

1K+ Views

Suppose we have a sorted linked list; we have to delete all duplicates such that each element appears only once.So, if the input is like [1, 1, 2, 3, 3, 3, 4, 5, 5], then the output will be [1, 2, 3, 4, 5]To solve this, we will follow these steps −dummy := make a new node with value -infnext of dummy := headcurr = dummywhile curr is non-zero, do −next = next of currwhile (next is not null and val of next is same as val of curr), do −next := next of nextnext of curr := nextcurr := ... Read More

Length of Last Word in C++

Arnab Chakraborty
Updated on 10-Jun-2020 12:06:26

1K+ Views

Suppose we have a string s. s can hold any English letters and white-spaces. We have to find the length of last word in the string. If there is no last word, then return 0.So, if the input is like "I love Programming", then the output will be 11To solve this, we will follow these steps −n := 0for each word temp in a string −n := size of tempreturn nExampleLet us see the following implementation to get a better understanding − Live Demo#include using namespace std; class Solution { public:    int lengthOfLastWord(string s){       stringstream str(s); ... Read More

Search Insert Position in C++

Arnab Chakraborty
Updated on 10-Jun-2020 12:06:01

556 Views

Suppose we have a sorted array arr and a target value, we have to find the index when the target is found. If that is not present, then return the index where it would be if it were inserted in order.So, if the input is like [1, 3, 4, 6, 6], and target = 5, then the output will be 3, as we can insert 5 at index 3, so the array will be [1, 3, 4, 5, 6, 6]To solve this, we will follow these steps−n := size of Aif n < 1, then −return 0low := 0, high ... Read More

Remove Element in Python

Arnab Chakraborty
Updated on 10-Jun-2020 12:04:05

213 Views

Suppose we have an array num and another value val, we have to remove all instances of that value in-place and find the new length.So, if the input is like [0, 1, 5, 5, 3, 0, 4, 5] 5, then the output will be 5.To solve this, we will follow these steps −count := 0for each index i of numsif nums[i] is not equal to val, then −nums[count] := nums[i]count := count + 1return countExampleLet us see the following implementation to get a better understanding − Live Democlass Solution:    def removeElement(self, nums, val):       count = 0   ... Read More

Difference between Method Overriding and Method Hiding in C#

Nitin Sharma
Updated on 09-Jun-2020 09:13:22

3K+ Views

In C# there are two mechanisms for redefining or providing the new implementation of a method of parent class by its child class and these two mechanisms are known as Method overriding and Method hiding. Now on the basis of how method re-implementation is done we can distinguish between both of them.Following are the important differences between Method Overriding and Method Hiding.Sr. No.KeyMethod OverridingMethod Hiding1DefinitionMethod Overriding is a mechanism to achieve polymorphism where the super class and sub class have same methods, including the parameters and signature and, when you call it using the sub class object, the implementation in ... Read More

Difference between SortedList and SortedDictionary in C#

Nitin Sharma
Updated on 09-Jun-2020 09:09:16

881 Views

Both SortedList and SortedDictionary in C# are the types of data structures used for data storage, now on the basis of characteristics and nature we can distinguish between both of them.Following are the important differences between SortedList and SortedDictionary.Sr. No.KeySortedListSortedDictionary1Memory organizationSortedList requires low memory for storage hence the memory status in its case is overhead.On other hand SortedDictionary requires more memory for storage so memory status in its case is not bottlenecked.2DesignedSortedList is internally implemented as in sortedList the elements are stored in a continuous block in memory.On other hand in SortedDictionary the elements are stored in separate object that ... Read More

Advertisements