Exam1

Original Session

Date: 11 Nov 2024

MCQ

  1. If Integer is 4 bytes, what is the size of the arr[15].
    1. Here size = memory allocated to array and not length.
  1. Python operators
    1. ** (exponential) a**b = a^b in hava
    1. //= (floor after divide)
  1. Coding Challenges
    1. 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];       
    }