The Surfer's Mentality

The Surfer's Mentality

Β·

3 min read

Overview

To be or not to be.

It all narrows down to the mindset of one's individual. When everything is in one's favour, all is well πŸ™ŒπŸ½. But life's a circle and no one can’t escape that phase. It depends on how we can handle the downside and bring some light within ourselves to move back to that top. That's where the surfer's πŸ„β€β™‚οΈ mentality comes in.

  • When a surfer gets up on a board, they enjoy the moment, even though they know the wave will eventually end. 🫣

    • But what's more thoughtful is that the next wave is up sooner or later. They must be prepared to ride those waves as well. 🧐

    • For eg: The ups and downs we face in our day-to-day lives. We should accept the fact and be ready for the next move. 🦾

  • At times, depending on the pressure the surfers need to wait for a long time before the waves kick in and start surfing.

    • Even after waiting for such a long time, they might not get the wave as good as the previous one. You have the choice to let the wave pass by. 🀌🏽

      • For eg: You can choose to let Stress and Anxiety pass by. To be honest it's not worth your energy and time. 🀧
    • So it's better to enjoy the wave and be at peace with it (You might get a better one. You never know. We have to focus only on the things which we can control). πŸ₯Ά

With high risks 🌊 (You have to go towards the wave) come high rewardsπŸ„β€β™‚οΈ. We must have experienced this in our lives. Even if that's not the case, take high risks (depending on one's situation obviously) to see how that rolls out. πŸ€“

References

The below video clearly explains how to apply the Surfer's mentality to our lives.

Bonus content

Question 7:

Explanation:

  • We are using the data structure called Stack (Last-in-first-out).

  • We start pushing the character to the stack for the starting cases '(', '{', '['.

  • When we encounter the closing case ')', '}', ']', we remove the top element from the stack and do a comparison like below.

    • Current: ')', Last: '('

    • Current: '}', Last: '{'

    • Current: ']', Last: '['

    • If the above cases don't match, we just return false right away since the ordering of parentheses is not valid.

Solution:

class Solution {

    private boolean isValidParentheses(char[] arr) {
        Stack<Character> stack = new Stack<>();
        int len = arr.length;
        for (int i=0; i<len; i++) {
            // Insert for starting cases
            if (arr[i] == '(' || arr[i] == '{' || arr[i] == '[') {
                stack.push(arr[i]);
            }
            // Remove the last inserted element for closing cases
            if (arr[i] == ')' || arr[i] == '}' || arr[i] == ']') {
                // Edge case where the stack itself can be empty.
                // Eg: Input: ")"
                if (stack.isEmpty()) {
                    return false;
                }
                char temp = stack.pop();
                if (!((arr[i] == ')' && temp == '(') || 
                    (arr[i] == '}' && temp == '{') || 
                    (arr[i] == ']' && temp == '['))) {
                        return false;
                }
            }
        }
        return stack.isEmpty();
    }

    public boolean isValid(String s) {
        char[] arr = s.toCharArray();
        return isValidParentheses(arr);
    }
}

Next problem:

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

Did you find this article valuable?

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

Β