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
Programming Articles - Page 1001 of 3366
818 Views
Before going to the solution let's understand about factorial. The factorial is a product of all the integers smaller than or equal to n. The mathematical representation is n!=n*(n -1)*(n-2)*(n-1)*....1 .For an example, 4! = 4*3*2*1 is 24. In this article let's try to find the different ways to find the factorial of a large number. Various Methods Following are multiple ways to find the factorial of a large number in Python − Using 'math' Module Using 'for' loop Using 'array' Using the ... Read More
494 Views
Suppose we have a list of rational numbers. We have to find their product using reduce function. The reduce() function applies a function with two arguments cumulatively on a list of objects from left to right.So, if the input is like fractions = [(5, 3), (2, 8), (6, 9), (5, 12), (7, 2)], then the output will be (175, 432) because 5/3 * 2/8 * 6/9 * 5/12 * 7/2 = (5*2*6*5*7)/(3*8*9*12*2) = 2100/5184 = 175/432.To solve this, we will follow these steps −fracs := a new listfor each f in frac, doinsert a new fraction object from (numerator, denominator) ... Read More
336 Views
Suppose we have a list of elements called nums, and a value k. We have to find those elements which have occurred at least k number of times.So, if the input is like nums = [2, 5, 6, 2, 6, 1, 3, 6, 3, 8, 2, 5, 9, 3, 5, 1] k = 3, then the output will be [2, 5, 6, 3]To solve this, we will follow these steps −c := a list containing frequencies of each elements present in numsres := a new listfor each key n in c, doif c[n] >= k, theninsert n at the end ... Read More
14K+ Views
Suppose we have an email address as string. We have to check whether this is valid or not based on the following conditions −The format must be username@company.domain formatUsername can only contain upper and lowercase letters, numbers, dashes and underscoresCompany name can only contain upper and lowercase letters and numbersDomain can only contain upper and lowercase lettersMaximum length of the extension is 3.We can use regular expression to validate the mail addresses. Regular expressions can be used by importing re library. To match a pattern we shall use match() function under re library.So, if the input is like s = ... Read More
310 Views
Suppose we have a number x and another number n. We have to find number of ways we can get x as sum of nth power of some unique numbers.So, if the input is like x = 100 n = 2, then the output will be 3 because possible solutions are 6^2 + 8^2, 10^2 and 1^2 + 3^2 + 4^2 + 5^2 + 7^2.To solve this, we will follow these steps −ans := 0Define a method called solve() this will take four parameters x, n, cn and cs, the initialvalues for cs = 0, cn = 1p := cn^nwhile ... Read More
946 Views
Suppose we have one alphanumeric string s. We have to sort it based on following conditionAll sorted lowercase letters will be placed before uppercase letters.All sorted uppercase letters will be placed before digits.All sorted odd digits will be placed before sorted even digits.So, if the input is like s = "HeLlo1234", then the output will be eloHL1324To solve this, we will follow these steps −Define a function f() . This will take ccode := 0if c is in upper case, thencode := 10^3otherwise when c is a digit, thencode := 10^6if ASCII of c is even, thencode := 10^9return code ... Read More
429 Views
Suppose we have a 2d list containing information about athletes. This information is rank, age, height. Each row contains information for different athletes. We also have another number k. We have to sort the data based on kth attribute.So, if the input is likeRankageheight125190235180333185426175535180And k = 1.then the output will beRankageheight125190426175333185235180535180[[1, 25, 190], [4, 26, 175], [3, 33, 185], [2, 35, 180], [5, 35, 180]]To solve this, we will follow these steps −Call the sort() function for the 2d array called infodefine one function that sort based on kth argument and pass it to the key parameter of sort() function.ExampleLet ... Read More
343 Views
Suppose we have two strings s and t (both contains lowercase English letters). We have to find a list of pairs of size 3, where each pair is in this form (l, k) here k is a string and l is its length. Now among these three pairs, first one contains substring of s and t which is longest common prefix p of these two strings, then the remaining part of s is s' and remaining part of t is t'. So final list will be like [(length of p, p), (length of s', s'), (length of t', t')].So, if ... Read More
21K+ Views
Suppose we have a string s. We have to compress this string into Run length encoding form. So when a character is repeated k number of times consecutively like 'bbbb' here letter 'b' is repeated four times consecutively, so the encoded form will be 'b4'. For single characters we shall not add the count into it.So, if the input is like s = "abbbaaaaaaccdaaab", then the output will be ab3a6c2da3bTo solve this, we will follow these steps −res := blank stringcnt := 1for i in range 1 to size of s - 1, doif s[i - 1] is same as ... Read More
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