Skip to content

Instantly share code, notes, and snippets.

View bijay-shrestha's full-sized avatar
👨‍🎓
MSCS Compro

Bijay Shrestha bijay-shrestha

👨‍🎓
MSCS Compro
View GitHub Profile
/**
* * 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}.
/**
* 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");
/**
* * 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
/**
*
* * 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
* *
/**
* * 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
* *
/**
* * 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]
/**
* * 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:
/**
* * 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).
/**
* * A Meera array is an array that contains the value 0 if and only if it contains a prime number.
* *
* * The array {7, 6, 0, 10, 1} is a Meera array because it contains a prime number (7)
* * and also contains a 0. The array {6, 10, 1} is a Meera array because it contains no prime
* * number and also contains no 0.
* *
* * The array {7, 6, 10} is not a Meera array because it contains a prime number (7) but does
* * not contain a 0.
* *
/**
* * A Bean 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 Bean array because
* * 2 = 3-1
* * 10 = 9+1
* * 3 = 2 + 1
* * 9 = 10 -1
* * Other Bean arrays include {2, 2, 3, 3, 3}, {1, 1, 1, 2, 1, 1} and {0, -1, 1}.
* *