Exam1
Original Session
Date: 11 Nov 2024
MCQ
- If Integer is 4 bytes, what is the size of the arr[15].
- Here size = memory allocated to array and not length.
- Python operators
- ** (exponential) a**b = a^b in hava
- //= (floor after divide)
- Coding Challenges
- Ugly number II leetcode here
- Ugly number II leetcode here
public int nthUglyNumber(int n) {
int[] arr = new int[n];
arr[0]=1;
int index2=0;
int index3=0;
int index5=0;
for (int i = 1; i < n; ++i) {
int multipleof2 = arr[index2] * 2;
int multipleof3 = arr[index3] * 3;
int multipleof5 = arr[index5] * 5;
arr[i]=Math.min(multipleof2, Math.min(multipleof3, multipleof5));
if (multipleof2 == arr[i]) {
index2++;
}
if (multipleof3 == arr[i]) {
index3++;
}
if (multipleof5 == arr[i]) {
index5++;
}
}
return arr[n-1];
}