
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
Found 10476 Articles for Python

177 Views
Suppose we have a number n; we have to find the smallest next higher number with the same number of 1s as n in binary form.So, if the input is like n = 7, then the output will be 11, as 7 in binary is 0111 and next higher from 7 with three ones would be 11 which is 1011 in binary.To solve this, we will follow these steps:copy := n, zeros := 0, ones := 0while copy is not 0 and copy is even, dozeros := zeros + 1copy = copy / 2while copy is odd, doones := ones ... Read More

238 Views
Suppose we have a 2D binary matrix. Here each row is sorted in ascending order with 0s coming before 1s, we have to find the leftmost column index with the value of 1. If there's no such result, return -1.So, if the input is like0001001100110010then the output will be 2, as the second column has left most 1 in entire matrix.To solve this, we will follow these steps:if matrix is empty, thenreturn -1N := row count of matrixM := column count of matrixi := 0, j := M - 1leftmost := -1while i < N and j >= 0, doif ... Read More

201 Views
Suppose we have a list of stock prices of a company in chronological order, we have to find the maximum profit we could have made from buying and selling the stock. We must buy before selling, and we must wait one day after selling the stock before buying again.So, if the input is like prices = [2, 6, 9, 4, 11], then the output will be 11, as we can buy at 2, then sell at 6, wait for a day, then buy at 4 and then sell at 11.To solve this, we will follow these steps:s := 0b := ... Read More

163 Views
Suppose we have a singly linked list, we have to rearrange it such that we take: the last node, and then the first node, and then the second last node, and then the second node, and so on.So, if the input is like [1, 2, 3, 4, 5, 6, 7, 8, 9], then the output will be [9, 1, 8, 2, 7, 3, 6, 4, 5, ]To solve this, we will follow these steps:c := nodel := a new listwhile c is not-null, doinsert value of c at the end of lc := next of cc := nodewhile c is ... Read More

890 Views
Suppose we have a string s consisting only two letters A and B, we have to find the minimum number of letters that need to be deleted from s to get all occurrences of As before all occurrences of Bs.So, if the input is like S = "AABAABB", then the output will be 1, as We can remove the last A to get AABBBTo solve this, we will follow these steps:a_right := number of occurrences of "A" in sb_left := 0ans := a_rightfor each index i and character c in s, doif c is same as "A", thena_right := a_right ... Read More

167 Views
Suppose we have a list of non-negative numbers called nums and also have an integer target. We have to find the the number of ways to arrange + and - in nums such that the expression equals to target.So, if the input is like nums = [2, 3, 3, 3, 2] target = 9, then the output will be 2, as we can have -2 + 3 + 3 + 3 + 2 and 2 + 3 + 3 + 3 – 2.To solve this, we will follow these steps:s := sum of all numbers in numsif (s + target) ... Read More

438 Views
Suppose we have a list of numbers called nums, we have to find the number of arithmetic subsequences of length ≥ 3. As we know an arithmetic sequence is a list of numbers where the difference between one number and the next is the same.So, if the input is like nums = [6, 12, 13, 8, 10, 14], then the output will be 3, as we have subsequences like: [6, 8, 10], [6, 10, 14], [12, 13, 14].To solve this, we will follow these steps:dp := a new mapn := size of numsres := 0for i in range 0 to ... Read More

2K+ Views
Suppose we have a list of numbers called nums, we have to find the number of contiguous arithmetic sequences of length ≥ 3. As we know an arithmetic sequence is a list of numbers where the difference between one number and the next number is the same.So, if the input is like nums = [6, 8, 10, 12, 13, 14], then the output will be 4, as we have the arithmetic sequences like: [6, 8, 10] [8, 10, 12] [6, 8, 10, 12] [12, 13, 14]To solve this, we will follow these steps −count := 0, ans := 0for i ... Read More

3K+ Views
Introduction..Assume you are asked to code a program to accept the number of tennis grandslam titles from the user and process them. We already know, Federer and Nadal share the maximum grandslam titles in Tennis which is 20 (As of 2020) while the minimum is 0, lot of players are still fighting to get their first grandslam title.Let us create a program to accept the titles.Note - Execute the program from terminal.Exampleimport argparse def get_args(): """ Function : get_args parameters used in .add_argument 1. metavar - Provide a hint to the user about the data type. - By default, ... Read More

847 Views
Introduction..If we were writing a program that performs arithematic operations on two numbers, we could define them as two positional arguments. But since they are the same kinds/python data types of arguments, it might make more sense to use the nargs option to tell argparse that you want exactly two of same types.How to do it..1. Let's write a program to substract two numbers (both the arguments are of same type).Exampleimport argparse def get_args(): """ Function : get_args parameters used in .add_argument 1. metavar - Provide a hint to the user about the data type. - By default, all ... Read More