Subjective vs Objective

Subjective vs Objective

Overview

We might have heard this term quite often on our day to day basis. Let's quickly understand what these terms mean.

  • Subjective most commonly means based on a person's perspective or preferences. (Maybe a Biased opinion)

    • Perception.
  • Objective most commonly means not influenced by or based on a personal viewpoint. (Possibly an Unbiased opinion)

    • Based on facts and reality.

Let's get to a quick real-life example of the above terms.

  • When I was writing code and explaining to one of my seniors, he said, "Please provide reasoning on why this way of coding is effective".

  • My instant response was it was easy to be understood by any developers (P.S. I love my code a lot 🤪). He immediately replied, "What kind of BS answer is this?".

  • Then, he explained the concept of subjective vs objective. He mentioned that what sounds convenient to you, might not say the same to others. So proper reasoning on why the code works effectively should be objective way rather than subjective.

  • That point was one of the moments in my life when we need to look at certain things objectively.

  • After that incident, I started to develop this habit to provide unbiased views on why I wrote something vs why I didn’t the other ways.

This applies to all professionals to provide or attempt to provide unbiased views to justify one's work.

But it's purely okay to provide subjective views as well.

We all learn from others and also I hope this post gives some clarity on subjective vs objective views.

References

Bonus Content

Question2:

In this post, I will cover the below problem in leetcode. 😁

Given a string s, find the length of the longest substring without repeating characters.

Explanation:

The problem is based on sliding-window and the usage of maps.

  • We need to increase the window size based on the duplicate entry present in the current maximum substring.

  • One interesting point to note here is that we switch the index to the maximum of the current sliding window index with the already present character index to avoid duplicate computations.

    • Math.max(map.get(arr[i], j);
  • We then return the maximum substring without repeating characters.

Solution:

class Solution {
    public int lengthOfLongestSubstring(String s) {
        int maxLength = 0;
        // Converting to array for easier reference.
        char[] arr = s.toCharArray();
        int len = arr.length;
        Map<Character, Integer> map = new HashMap<>();
        for (int i = 0, j=0; i<len; i++) {
            // Check if the key is already present.
            // If so move the pointer to the max index, coz anyways there will be a duplicate entry present if we go on iterating one by one.
            if (map.containsKey(arr[i])) {
                j = Math.max(map.get(arr[i]), j);
            }
            // Get the max length
            maxLength = Math.max(maxLength, i - j + 1);
            // Adding the ith index + 1 to ensure we get the maximum length (0-based indexing)
            map.put(arr[i], i + 1);
        }
        return maxLength;
    }
}

Next problem:

In the next post, I will cover the below problem.

Did you find this article valuable?

Support Karthick Ramjee by becoming a sponsor. Any amount is appreciated!