Found 26504 Articles for Server Side Programming

Day of the Week in C++

Arnab Chakraborty
Updated on 19-Feb-2021 07:24:45

7K+ Views

Suppose we have a date (day, month and year). From this date, we have to find the day of the week of that given date. To solve this we will use Zeller’s Algorithm. The formula to find weekday using Zeller’s Algorithm is here𝑤=$$\lgroup d+\lfloor \frac{13(m+1)}{5} \rfloor+y+\lfloor\frac{y}{4} \rfloor+\lfloor\frac{c}{4} \rfloor+5c \rgroup mod 7$$The formula is containing some variables; They are −d − The day of the date.m − It is the month code. For March to December, it is 3 to 12, for January it is 13, and for February it is 14. When we consider January or February, then the given ... Read More

N-th Tribonacci Number in C++

Arnab Chakraborty
Updated on 28-Apr-2020 11:07:03

406 Views

Suppose we have a value n, we have to generate n-th Tribonacci number. The Tribonacci numbers are similar to the Fibonacci numbers, but here we are generating a term by adding three previous terms. Suppose we want to generate T(n), then the formula will be like below −T(n) = T(n - 1) + T(n - 2) + T(n - 3)The first few numbers to start, are {0, 1, 1}We can solve them by following this algorithm −Algorithm• first := 0, second := 1, third := 1 • for i in range n – 3, do    o next := first ... Read More

Hamming Distance in Python

Arnab Chakraborty
Updated on 28-Apr-2020 11:05:39

4K+ Views

Consider we have two integers. We have to find the Hamming distance of them. The hamming distance is the number of bit different bit count between two numbers. So if the numbers are 7 and 15, they are 0111 and 1111 in binary, here the MSb is different, so the Hamming distance is 1.To solve this, we will follow these steps −For i = 31 down to 0b1 = right shift of x (i AND 1 time)b2 = right shift of y (i AND 1 time)if b1 = b2, then answer := answer + 0, otherwise answer := answer + ... Read More

Fizz Buzz in Python

Arnab Chakraborty
Updated on 28-Apr-2020 11:03:59

4K+ Views

Suppose we have a number n. We have to display a string representation of all numbers from 1 to n, but there are some constraints.If the number is divisible by 3, write Fizz instead of the numberIf the number is divisible by 5, write Buzz instead of the numberIf the number is divisible by 3 and 5 both, write FizzBuzz instead of the numberTo solve this, we will follow these steps −For all number from 1 to n, if a number is divisible by 3 and 5 both, print “FizzBuzz”otherwise when the number is divisible by 3, print “Fizz”otherwise when ... Read More

Range Sum Query - Immutables in C++

Arnab Chakraborty
Updated on 28-Apr-2020 10:50:14

173 Views

Suppose we have an array of integers. We have to find the sum of the elements present from index i to j. Two things we have to keep in mind that the array will be immutable, so elements will not be altered, and there will be multiple such queries. So we have to care about the execution time for a large number of queries. Suppose the array is like A = [5, 8, 3, 6, 1, 2, 5], then if query is (A, 0, 3), then it will be 5 + 8 + 3 + 6 = 22.To solve this, ... Read More

Move Zeroes in Python

Arnab Chakraborty
Updated on 28-Apr-2020 10:46:18

1K+ Views

Suppose we have an array to hold some numbers. There are non-zero values as well as zero values. So we have to send all zeros to the right without changing the relative order of other numbers. So if the array is like [0, 1, 5, 0, 3, 8, 0, 0, 9], then the final array will be [1, 5, 3, 8, 9, 0, 0, 0, 0]To solve this, we will follow these steps −Suppose index = 0for i = 0 to the length of Aif A[i] != 0, thenA[index] := A[i]index := index + 1for i = index to the ... Read More

Missing Number in Python

Arnab Chakraborty
Updated on 28-Apr-2020 10:43:48

441 Views

Suppose we have a list of numbers from 0 to n. There is one number that is missing. We have to find the missing number in an efficient approach. So if A = [0, 1, 2, 3, 4, 5, 7, 8, 9], missing number is 6.To solve this, we will use the binary search approach.sort the list in ascending orderhigh = length of A, and low = 0while low < high, domid = low + (high – low)/2if A[mid] > midhigh = midotherwiselow = mid + 1return lowExampleLet us see the following implementation to get a better understanding − Live Democlass ... Read More

Ugly Number in C++

Arnab Chakraborty
Updated on 28-Apr-2020 10:39:27

968 Views

Ugly numbers are those numbers whose prime factors are 2, 3 or 5. From 1 to 15, there are 11 ugly numbers 1, 2, 3, 4, 5, 6, 8, 9, 10, 12, 15. The numbers 7, 11, 13 are not ugly because they are prime. The number 14 is not ugly because in its prime factor the 7 will come. So suppose we want to check the 10th ugly number. The value will be 12.Let us see the following algorithm to get an idea −AlgorithmgetUglyNumbers(n)Input − The number of terms.Output − Find nth Ugly numbers.Begin    define array named uglyNum ... Read More

Valid Anagram in Python

Arnab Chakraborty
Updated on 28-Apr-2020 10:33:32

651 Views

Anagrams are basically all permutations of a given string or pattern. This pattern searching algorithm is slightly different. In this case, not only the exact pattern is searched, it searches all possible arrangements of the given pattern in the text. So if the inputs are “ANAGRAM” and “NAAGARM”, then they are anagram, but “cat” and “fat” are not an anagramTo solve this, we will convert the string into a list of characters, then sort them, if two sorted lists are same then they are anagram.Example (Python)Let us see the following implementation to get a better understanding − Live Democlass Solution(object):   ... Read More

Delete Node in a Linked List in Python

sudhir sharma
Updated on 31-Jul-2025 12:49:23

4K+ Views

A linked list is a linear data structure where each element is a separate object, commonly referred to as a node. Each node contains two fields: the data and a pointer to the next node in the list. In this article, we'll learn how to delete a node from a singly linked list using Python. Suppose we have a linked list with a few elements. Our task is to delete a specific node, given only access to that node - not the head of the list. For example: Input: 1 → 3 → 5 → 7 → ... Read More

Advertisements