General Software Engineer Assessment (INDIA ONLY) | SalesForce

I gave the salesforce OA literally 5mins ago. The entire test was for 125 points Q1 - 50 points and Q2 - 75 points and there were 75mins for the test

The questions were very very easy compared what I was expecting, the only problem is I finished the 75mins test in 9mins I hope that isn't flagged.
I was able to do it so soon because Q1 was extremely easy and I had literally solved Q2 the same day as it is the first question that appears when you filter for salesforce questions on leetcode.

Q1. Remove repeats from a LinkedList


def sol(head):
    if not head:
        return head

    hash_set = set()
    hash_set.add(head.val)

    curr = head
    while curr.next:
        if curr.next.val in hash_set:
            curr.next = curr.next.next
        else:
            hash_set.add(curr.next.val)
            curr = curr.next
    return head

Q2. Minimum Operations to Reduce an Integer to 0

class Solution:
    def minOperations(self, n: int) -> int:
        cnt = 0
        while n:
            exp = 1
            while 2**exp < n: exp += 1
            n = min(abs(2**exp - n), abs(2**(exp-1) - n))
            cnt += 1
        return cnt
Comments (2)