
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 33676 Articles for Programming

909 Views
Suppose we have three sides. We have to check whether these three sides are forming a triangle or not.So, if the input is like sides = [14,20,10], then the output will be True as 20 < (10+14).To solve this, we will follow these steps −sort the list sidesif sum of first two sides

419 Views
Suppose we have a string s. We have to check whether the vowels present in s are in alphabetical order or not.So, if the input is like s = "helloyou", then the output will be True as vowels are e, o, o, u all are in alphabetical order.To solve this, we will follow these steps −character := character whose ASCII is 64for i in range 0 to size of s - 1, doif s[i] is any one of ('A', 'E', 'I', 'O', 'U', 'a', 'e', 'i', 'o', 'u'), thenif s[i] < character, thenreturn Falseotherwise, character := s[i]return TrueLet us see ... Read More

493 Views
Suppose we have two numbers x and y. We have to check whether these two numbers differ at one-bit position or not.So, if the input is like x = 25 y = 17, then the output will be True because x = 11001 in binary and y = 10001. Only one-bit position is different.To solve this, we will follow these steps −z = x XOR yif number of set bits in z is 1, thenreturn Truereturn FalseLet us see the following implementation to get better understanding −Example CodeLive Demodef bit_count(n): count = 0 while n: ... Read More

175 Views
Suppose we have an array nums. We have to check whether the sum of all prime elements in the given array is also prime or notSo, if the input is like nums = [1, 2, 4, 5, 3, 3], then the output will be True as sum of all primes are (2+5+3+3) = 13 and 13 is also prime.To solve this, we will follow these steps −MAX := 10000sieve := a list of size MAX and fill with trueDefine a function generate_list_of_primes()sieve[0] := False, sieve[1] := Falsefor i in range 2 to MAX - 1, doif sieve[i] is true, thenfor ... Read More

215 Views
Suppose we have a number n. We have to check whether the sum of the absolute difference of adjacent digit pairs is prime or not.So, if the input is like n = 574, then the output will be True as |5-7| + |7-4| = 5, this is prime.To solve this, we will follow these steps −num_str := n as stringtotal := 0for i in range 1 to size of num_str - 1, dototal := total + |digit at place num_str[i - 1] - digit at place num_str[i]|if total is prime, thenreturn Truereturn FalseLet us see the following implementation to get ... Read More

2K+ Views
Suppose we have a straight line in the form y = mx + b, where m is slope and b is y-intercept. And have another coordinate point (x, y). We have to check whether this coordinate point lies on that straight line or not.So, if the input is like m = 3 b = 5 point = (6, 23), then the output will be True as if we put the given x and y coordinate values on the straight line equation then it will satisfy.To solve this, we will follow these steps −if y of point is same as (m ... Read More

177 Views
Suppose we have a number n. We have to check whether the number has only two set bits at first and last position or not.So, if the input is like n = 17, then the output will be True as the binary representation of n is 10001, there is only two 1's at first and last position.To solve this, we will follow these steps −if n is same as 1, thenreturn Truereturn true if n - 1 is power of 2, otherwise falseLet us see the following implementation to get better understanding −Example CodeLive Demodef is_pow_of_two(n): return (n & ... Read More

182 Views
Suppose we have two numbers x and y. We have to concatenate them and check whether the resultant number is perfect square or not.So, if the input is like x = 2 y = 89, then the output will be True as after concatenating the number will be 289 which is 17^2.To solve this, we will follow these steps −first_num := x as stringsecond_num := y as stringres_num := concatenate first_num and second_num then convert to integersqrt_val := integer part of square root of(res_num)if sqrt_val * sqrt_val is same as res_num, thenreturn Truereturn FalseLet us see the following implementation to ... Read More

561 Views
Suppose we have a number n. We have to check whether the number can be a perfect square number by adding 1 with it or not.So, if the input is like n = 288, then the output will be True as after adding 1, it becomes 289 which is same as 17^2.To solve this, we will follow these steps −res_num := n + 1sqrt_val := integer part of square root of(res_num)if sqrt_val * sqrt_val is same as res_num, thenreturn Truereturn FalseLet us see the following implementation to get better understanding −Example CodeLive Demofrom math import sqrt def solve(n): ... Read More

206 Views
Suppose we have a linked list, we have to check whether the length of it is odd or even.So, if the input is like head = [5, 8, 7, 4, 3, 6, 4, 5, 8], then the output will be Odd.To solve this, we will follow these steps −while head is not null and next of head is not null, dohead := next of next of headif head is null, thenreturn "Even"return "Odd"Let us see the following implementation to get better understanding −Example CodeLive Democlass ListNode: def __init__(self, data, next = None): self.val = data ... Read More