Mixed experience with Cursor IDE

Cursor is a great IDE, a fork of VSCode with embedded AI. Few things that I really liked about it:

1. The next action completion is great. Adjusting the code across all the files is magnificent

2. The chat function on the side is really helpful too

3. The inference based on the name of the functions is also phenomenal. For example, all I had to do was to write the name of the functions for LCM and GCD, and it wrote all this code for me:


Now what I don't like:

4. Tries to be extra smart all the time. It really disrupts the flow, especially if you need time to think about what you need to write. There is a bit of tuning that is needed there

The problem was the one below, try installing and playing with it too.

Find the Maximum Factor Score of Array - LeetCode

3334. Find the Maximum Factor Score of Array
Medium

You are given an integer array nums.

The factor score of an array is defined as the product of the LCM and GCD of all elements of that array.

Return the maximum factor score of nums after removing at most one element from it.

Note that both the LCM and GCD of a single number are the number itself, and the factor score of an empty array is 0.

The term lcm(a, b) denotes the least common multiple of a and b.

The term gcd(a, b) denotes the greatest common divisor of a and b.

 

Example 1:

Input: nums = [2,4,8,16]

Output: 64

Explanation:

On removing 2, the GCD of the rest of the elements is 4 while the LCM is 16, which gives a maximum factor score of 4 * 16 = 64.

Example 2:

Input: nums = [1,2,3,4,5]

Output: 60

Explanation:

The maximum factor score of 60 can be obtained without removing any elements.

Example 3:

Input: nums = [3]

Output: 9

 

Constraints:

  • 1 <= nums.length <= 100
  • 1 <= nums[i] <= 30
Accepted
15,433
Submissions
39,586


    public long MaxScore(int[] nums) 
    {
        long maxScore = 0;

        long lcm = nums[0];
        long gcd = nums[0];
        for(int i = 1; i < nums.Length; i++)
        {
            lcm = LeastCommonMultiple(lcm, nums[i]);
            gcd = GreatestCommonDivisor(gcd, nums[i]);
        }
        maxScore = lcm*gcd;

        for(int i = 0; i < nums.Length; i++)
        {
            lcm = -1;
            gcd = -1;
            for(int j = 0; j < nums.Length; j++)
            {
                if(i == j) continue;
                lcm = (lcm == -1) ? nums[j] : LeastCommonMultiple(lcm, nums[j]);
                gcd = (gcd == -1) ? nums[j] : GreatestCommonDivisor(gcd, nums[j]);
            }
            maxScore = Math.Max(maxScore, lcm*gcd);
        }

        return maxScore;

    }

    public long LeastCommonMultiple(long a, long b)
    {
        return a * b / GreatestCommonDivisor(a, b);
    }

    public long GreatestCommonDivisor(long a, long b)
    {
        while(b != 0)
        {
            long temp = b;
            b = a % b;
            a = temp;
        }
        return a;
    }

Comments

Popular posts from this blog

Advent of Code - Day 6, 2024: BFS and FSM

Golang vs. C#: performance characteristics (simple case study)

Advent of Code - Day 7, 2024: Backtracking and Eval