This file contains 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
#!/bin/bash | |
while getopts h:u:p:t:d: flag | |
do | |
case "${flag}" in | |
h) host=${OPTARG};; | |
u) username=${OPTARG};; | |
p) password=${OPTARG};; | |
t) target=${OPTARG};; | |
d) destination=${OPTARG};; | |
esac |
This file contains 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
/* | |
Maximum Average Subarray I | |
Given an array consisting of n integers, find the contiguous subarray of given length k that has the maximum average value. And you need to output the maximum average value. | |
Example 1: | |
Input: [1,12,-5,-6,50,3], k = 4 | |
Output: 12.75 | |
Explanation: Maximum average is (12-5-6+50)/4 = 51/4 = 12.75 |
This file contains 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
/* | |
Count Primes | |
Count the number of prime numbers less than a non-negative number, n. | |
Example: | |
Input: 10 | |
Output: 4 | |
Explanation: There are 4 prime numbers less than 10, they are 2, 3, 5, 7. |
This file contains 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
/* | |
Rotate Function | |
Given an array of integers A and let n to be its length. | |
Assume Bk to be an array obtained by rotating the array A k positions clock-wise, we define a "rotation function" F on A as follow: | |
F(k) = 0 * Bk[0] + 1 * Bk[1] + ... + (n-1) * Bk[n-1]. | |
Calculate the maximum value of F(0), F(1), ..., F(n-1). |
This file contains 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
<?php | |
/* | |
Range Sum Query 2D - Immutable | |
Given a 2D matrix matrix, find the sum of the elements inside the rectangle defined by its upper left corner (row1, col1) and lower right corner (row2, col2). | |
Example: | |
Given matrix = [ | |
[3, 0, 1, 4, 2], | |
[5, 6, 3, 2, 1], | |
[1, 2, 0, 1, 5], |
This file contains 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
<?php | |
/* | |
Find First and Last Position of Element in Sorted Array | |
Given an array of integers nums sorted in ascending order, find the starting and ending position of a given target value. | |
Your algorithm's runtime complexity must be in the order of O(log n). | |
If the target is not found in the array, return [-1, -1]. |
This file contains 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
<?php | |
/* | |
In Pascal's triangle, each number is the sum of the two numbers directly above it. | |
Example: | |
Input: 5 | |
Output: | |
[ |
This file contains 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
<?php | |
/* | |
Given two arrays, write a function to compute their intersection. | |
Example 1: | |
Input: nums1 = [1,2,2,1], nums2 = [2,2] | |
Output: [2,2] | |
Example 2: |
This file contains 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
<?php | |
/* | |
Write a program that outputs the string representation of numbers from 1 to n. | |
But for multiples of three it should output “Fizz” instead of the number and for the multiples of five output “Buzz”. For numbers which are multiples of both three and five output “FizzBuzz”. | |
Example: | |
n = 15, |
This file contains 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: | |
class Solution { public int solution(int[] A); } | |
that, given an array A of N integers, returns the smallest positive integer (greater than 0) that does not occur in A. | |
For example, given A = [1, 3, 6, 4, 1, 2], the function should return 5. | |
Given A = [1, 2, 3], the function should return 4. |
NewerOlder