Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Server Side Programming Articles - Page 863 of 2650
15K+ Views
Suppose we have a string s. We have to swap all odd positioned elements with the even positioned elements. So finally we shall get a permutation of s where elements are pairwise swapped.So, if the input is like s = "programming", then the output will be "rpgoarmmnig"To solve this, we will follow these steps −s := make a list from the characters of sfor i in range 0 to size of s - 1, increase by 2, doswap s[i], s[i+1] with s[i+1], s[i]join characters from s to make whole string and returnExampleLet us see the following implementation to get better ... Read More
5K+ Views
Suppose we want to do complex number tasks by defining a complex number class with following operations −add() to add two complex numberssub() to subtract two complex numbersmul() to multiply two complex numbersdiv() to divide two complex numbersmod() to get modulus of complex numbersThe complex numbers will be shown in the form (a + bi). We have two complex numbers, will perform these operations on them. Inside the class we overload the add(), sub(), mul() and div() methods so that we can use the operators to perform the operations. We also overload __str__() method to print the complex number in ... Read More
1K+ Views
Suppose we have a number n. We have to print a triangle with n rows and each line will hold line number i, i number of times.So, if the input is like n = 5, then the output will be1 22 333 4444 55555To solve this, we will follow these steps −for i in range 1 to n, dodisplay (integer part of (10^i)/9*i)go to next lineExampleLet us see the following implementation to get better understanding −def solve(n): for i in range(1,n+1): print((10**i)//9*i) n = 8 solve(n)Input8 Output1 22 333 4444 55555 666666 7777777 88888888
471 Views
Suppose we have an array with n different English letters. We also have another value k. We can select k different indices (1-indexed) with uniform distribution. We have to find the probability that at least one of the k indices selected will contain the letter 'a'.So, if the input is like letters = ['a', 'c', 'a', 'b', 'l', 'a', 'b', 'z'] k = 2, then the output will be 64.28%. There are combinations like (1, 2), (1, 3) like there are 28 combinations but some of them like (1, 2), (1, 3), (6, 7) such 18 pairs are holding 7, ... Read More
15K+ Views
Suppose we have a number n. We have to generate Pascal's triangle up to n lines. The Pascal's triangle will be look like this −The property of Pascal's triangle is the sum of each adjacent two numbers of previous row is the value of the number which is placed just below on the second row. For example, the first 10 at row 6 is sum of 4 and 6 at row 5 and second 10 is sum of two numbers 6 and 4 at row 5.So, if the input is like n = 5, then the output will be ... Read More
4K+ Views
Suppose we have a number n. We have to find a triangle with n rows and each row contains palindrome.So, if the input is like n = 5, then the output will be1 121 12321 1234321 123454321To solve this, we will follow these steps −for i in range 1 to n, dodisplay ((integer part of (10^i) - 1)/9)^2go to next lineExampleLet us see the following implementation to get better understanding −def solve(n): for i in range(1,n+1): print((((10**i) - 1)//9)**2) n = 8 solve(n)Input8 Output 1 121 12321 1234321 123454321 12345654321 1234567654321 123456787654321
6K+ Views
Suppose we have a number n. We have to find the nth Fibonacci term by defining a recursive function.So, if the input is like n = 8, then the output will be 13 as first few Fibonacci terms are 0, 1, 1, 2, 3, 5, 8, 13, 21, 34...To solve this, we will follow these steps −Define a function solve() . This will take nif n
318 Views
Suppose we have an array nums containing size of n different cubes, they are placed horizontally. We have to make a pile of cubes vertically. The new cube should follow −if ith cube is on top of jth cube, then side length of jth one must be greater or equal to side length of ith one.When we are making the vertical pile, we can only take cubes from left side or right side but not from the middle. We have to check whether we can pile them up or not.So, if the input is like nums = [1, 2, 3, ... Read More
8K+ Views
Suppose we have two numbers a and b. We have to find the GCD of these two numbers in recursive way. To get the GCD we shall use the Euclidean algorithm.So, if the input is like a = 25 b = 45, then the output will be 5To solve this, we will follow these steps −Define a function gcd() . This will take a, bif a is same as b, thenreturn aotherwise when a < b, thenreturn gcd(b, a)otherwise, return gcd(b, a - b)ExampleLet us see the following implementation to get better understanding −def gcd(a, b): if a == ... Read More
615 Views
Suppose we have a company name as string. We have to find the most common three characters from the company name and show them by following these rules −Pick most frequent three lettersSort them in descending orderIf the frequencies of some characters are same then take by their alphabetical orderSo, if the input is like s = "TUTORIALSPOINT", then the output will be [[3, 'T'], [2, 'I'], [2, 'O']]To solve this, we will follow these steps −x := a map containing letters and frequencies of letters in sres := a new listfor each i in x, doinsert pair (x[i], i) ... Read More