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 1883 of 3366
300 Views
Suppose we have two integers L and R, we have to find the count of numbers in the range [L, R] (inclusive) having a prime number of set bits in their binary form.So, if the input is like L = 6 and R = 10, then the output will be 4, as there are 4 numbers 6(110), 7(111), 9(1001), 10(1010), all have prime number of set bits.To solve this, we will follow these steps −count := 0for j in range L to R, doif set bit count of j is in [2, 3, 5, 7, 11, 13, 17, 19], thencount ... Read More
282 Views
Following is the Java code to find the perimeter of a cylinder −Example Live Demoimport java.io.*; public class Demo{ static int find_peri(int dia, int ht){ return 2*(dia + ht); } public static void main(String[] args){ int dia = 7; int ht = 15; System.out.println("The perimeter of the cylinder is " + find_peri(dia, ht) + " units"); } }OutputThe perimeter of the cylinder is 44 unitsA class named Demo defines a static function that takes in two values, diameter and height. This function computes the sum ... Read More
397 Views
Suppose we have a dictionary words, and we have to find the minimum length word from a given dictionary words, it has all the letters from the string licensePlate. Now such a word is said to complete the given string licensePlate. Here, we will ignore case for letters. And it is guaranteed an answer exists. If there are more than one answers, then return answer that occurs first in the array.The license plate there may be same letter occurring multiple times. So when a licensePlate of "PP", the word "pile" does not complete the licensePlate, but the word "topper" does.So, ... Read More
442 Views
Suppose we have an integer array called nums, now there is always exactly one largest element. We have to check whether the largest element in the array is at least twice as much as every other number in the array. If it is so, then we have to find the index of the largest element, otherwise return -1.So, if the input is like [3, 6, 1, 0], then the output will be 1, as 6 is the largest number, and for every other number in the array x, 6 is more than twice as big as x. As the index ... Read More
3K+ Views
Following is the Java code to find the largest prime factor of a number −Example Live Demoimport java.io.*; import java.util.*; public class Demo{ static long maxPrimeFactors( long val){ long max_prime = -1; while (val % 2 == 0) { max_prime = 2; val >>= 1; } for (int i = 3; i 2) max_prime = val; return max_prime; } public static void main(String[] args){ int val = 148592; ... Read More
888 Views
Suppose there is a staircase, here the i-th step will be some non-negative cost value cost[i] assigned. When we pay the cost, we can either climb one or two steps. We have to find minimum cost to reach the top of the floor, and we also can either start from the step with index 0, or the step with index 1.So, if the input is like cost = [12, 17, 20], then the output will be 17, The cheapest position to start from step 1 as we have to pay that cost and go to the top.To solve this, we ... Read More
194 Views
Followimg is the code to implement String formatting in Java using % −Example Live Demopublic class Demo { public static void main(String args[]){ String my_str = " sample."; String concat_Str = String.format("This is a" + "%s", my_str); String format_str_1 = String.format("The value is %.4f", 78.92367); System.out.println(concat_Str); System.out.println(format_str_1); } }OutputThis is a sample. The value is 78.9237A class named Demo contains the main function. Here a string value is defined, which is used to format the string, by concatenating it to another variable. Similarly, a ... Read More
1K+ Views
Suppose we have a list of sorted characters’ letters. This is containing only lowercase letters, now we have a target letter t, we have to find the smallest element in the list that is larger than the given target.And letters also wrap around. So, if the target is t = 'z' and letters = ['a', 'b'], the answer is 'a'.So, if the input is like ["c", "f", "j"], t = 'a', then the output will be 'c'.To solve this, we will follow these steps −l := 0r := size of letters - 1while l target, thenr := mid -1otherwise, ... Read More
570 Views
In this article, we will learn to write a Java program to calculate the sum of cubes of the first n natural numbers. Understanding the Cube Sum Formula The sum of cubes of the first n natural numbers follows a mathematical formula − S = 13 + 23 + 33 + ... + n3 = { ( n ( n + 1 ) ) / 2 }2 Different Approaches Following are the two different approaches to printing the cube sum of first n natural numbers − Using a Loop Using a ... Read More
552 Views
Suppose we have a list of words representing an English Dictionary, we have to find the longest word in the given word list that can be built one character at a time by other words in words. If there is more than one possible answer, then return the longest word with the smallest lexicographical order. If there is no answer, then return the empty string.So, if the input is like ["h", "he", "hel", "hell", "hello"], then the output will be "hello"To solve this, we will follow these steps −trie := a new mapDefine a function insert(). This will take wordnow ... Read More