Junit_Assignment24
Junit_Assignment24
company;
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.List;
if (s != null) {
if(s==""){
return "no input";
}
Example 1:
Input: gain = [-5,1,5,0,-7]
Output: 1
Explanation: The altitudes are [0,-5,-4,1,1,-6]. The highest is 1 */
public static int calculateHighestAltitude(int[] gain) {
int currentAltitude = 0;
int highestAltitude = 0;
/*
For two strings s and t, we say "t divides s" if and only if s = t + t +
t + ... + t + t (i.e., t is concatenated with itself one or more times).
Given two strings str1 and str2, return the largest string x such that x
divides both str1 and str2.
Example 1:
Input: str1 = "ABCABC", str2 = "ABC"
Output: "ABC"
Example 2:
Input: str1 = "ABABAB", str2 = "ABAB"
Output: "AB"
*/
public String gcdOfStrings(String str1, String str2) {
String output = "";
if(!(str1+str2).equals(str2+str1)){
return output;
}else{
BigInteger b1= new
BigInteger(String.valueOf(str1.length()));
BigInteger b2= new
BigInteger(String.valueOf(str2.length()));
BigInteger val = b1.gcd(b2);
output = str1.substring(0, val.intValue());
}
return output;
}
/*
You are given an integer array nums consisting of n elements,
and an integer k. Find a contiguous subarray whose length is
equal to k that has the maximum average value and return this
value. Any answer with a calculation error less than
10-5 (ten to the power of negative five) will be accepted.
Example 1:
}
return filteredList;
}
IntelliJ