This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* * Write a function named countDigit that returns the number of times that a given digit appears in a | |
* * positive number. | |
* * | |
* * For example countDigit(32121, 1) would return 2 because there are two 1s in 32121.Other examples: | |
* * countDigit(33331, 3) returns 4 | |
* * countDigit(33331, 6) returns 0 | |
* * countDigit(3, 3) returns 1 | |
* * | |
* * The function should return -1 if either argument is negative, so |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* * Write a function named minDistance that returns the smallest distance between two factors of a number. | |
* * | |
* * For example, consider 13013 = 1*7*11*13. Its factors are 1, 7, 11, 13 and 13013. | |
* * minDistance(13013) would return 2 because the smallest distance between any two factors is 2 (13 - 11 = 2). | |
* * | |
* * As another example, minDistance (8) would return 1 because the factors of 8 are 1, 2, 4, 8 | |
* * and the smallest distance between any two factors is 1 (2 – 1 = 1). | |
* * | |
* * The function signature is |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* * A Nice array is defined to be an array where for every value n in the array, there is also an | |
* * element n-1 or n+1 in the array. | |
* * | |
* * For example, {2, 10, 9, 3} is a Nice array because | |
* * 2 = 3-1 | |
* * 10 = 9+1 | |
* * 3 = 2 + 1 | |
* * 9 = 10 -1 | |
* * Other Nice arrays include {2, 2, 3, 3, 3}, {1, 1, 1, 2, 1, 1} and {0, -1, 1}. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Print Triangle of Ones. | |
*/ | |
package com.basic.practice; | |
public class TriangleOfOne { | |
public static void main(String[] args) { | |
for (int i = 0; i < 5; i++) { | |
for (int j = 0; j <= i; j++) { | |
System.out.print("1"); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* * A wave array is defined to an array which does not contain two even numbers or two odd | |
* * numbers in adjacent locations. So {7, 2, 9, 10, 5}, {4, 11, 12, 1, 6}, {1, 0, 5} and {2} are all wave | |
* * arrays. But {2, 6, 3, 4} is not a wave array because the even numbers 2 and 6 are adjacent to each | |
* * other. | |
* * | |
* * Write a function named isWave that returns 1 if its array argument is a Wave array, otherwise it | |
* * returns 0. | |
* * | |
* * If you are programming in Java, the function signature is |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* | |
* * Given an integer x, return true if x is palindrome integer. | |
* * | |
* * An integer is a palindrome when it reads the same backward as forward. For example, 121 is palindrome while 123 is not. | |
* * | |
* * Example 1: | |
* * Input: x = 121 | |
* * Output: true | |
* * |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* * Given a signed 32-bit integer x, return x with its digits reversed. | |
* * If reversing x causes the value to go outside the signed 32-bit integer range [-231, 231 - 1], then return 0. | |
* * | |
* * Assume the environment does not allow you to store 64-bit integers (signed or unsigned). | |
* * | |
* * Example 1: | |
* * Input: x = 123 | |
* * Output: 321 | |
* * |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* * Given an array of integers nums and an integer target, return indices of the two numbers such that they add up to target. | |
* * | |
* * You may assume that each input would have exactly one solution, and you may not use the same element twice. | |
* * | |
* * You can return the answer in any order. | |
* * | |
* * Example 1: | |
* * Input: nums = [2,7,11,15], target = 9 | |
* * Output: [0,1] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* * Given an integer array nums sorted in non-decreasing order, return an array of the squares of each number sorted in non-decreasing order. | |
* * Example 1: | |
* * | |
* * Input: nums = [-4,-1,0,3,10] | |
* * Output: [0,1,9,16,100] | |
* * Explanation: After squaring, the array becomes [16,1,0,9,100]. | |
* * After sorting, it becomes [0,1,9,16,100]. | |
* * | |
* * Example 2: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* * Given an array nums of integers, return how many of them contain an even number of digits. | |
* * | |
* * Example 1: | |
* * Input: nums = [12,345,2,6,7896] | |
* * Output: 2 | |
* * Explanation: | |
* * - 12 contains 2 digits (even number of digits). | |
* * - 345 contains 3 digits (odd number of digits). | |
* * - 2 contains 1 digit (odd number of digits). |