Never allow yourself to skip more than one day in a row.
Overview
We all must have faced this situation once or many in our lifetimes. Try to create a habit and fail miserably.
We all strive hard to develop a habit
and at some point in time, we fail to maintain it (possibly due to various reasons). We then regret how we missed it and try to start it back again (which is very hard the second time).
Below is a quick summary of this 2-day rule
on how you can create a habit and succeed at it.
Disclaimer: The below technique requires a lot of self-discipline.
The first step is to
choose a realistic goal
that we strive to achieve over a period of time. (Be it being healthy or any self-improvement habit)Once we have committed to a goal, the next step is to
keep track of it
. The below image is a reference on how we can create a habit easily without any regrets.Missing a day is really not a big deal. But a second makes it that much easier to miss the third day, a week, a month.
At which point you don't really remember the activity at all.
In my personal life, I always wanted to create a habit of maintaining a healthy lifestyle
. I want to hit the gym at least 3-4 times per week
in the coming year (2023). Bringing up a new habit requires a lot of self-motivation and not getting trapped with the famous New year resolutions
.
In order to follow this rule, we shouldn’t skip 2 days in a row. I did create a reminder to do 50-100 squats daily for the days when I don't go to the gym. With this, I will get the satisfaction (or trick my brain to say) that my habit is not skipped and is on track.
If you set the right rules for yourself, based on what you value most, it will help you live a life that you’ve always imagined.
— Matt D’Avella
References
The below video clearly explains what this 2-day rule is all about.
Bonus content
Question 5:
Explanation:
The problem is slightly more tricky than https://leetcode.com/problems/two-sum/.
We first sort the array to ensure we find
i, j, k-th index
without any clash.Next, we iterate by fixing
i-th
index and find thej-th
andk-th
index.If we find
sum == 0
, we add it to the result array and then skip thej-th
andk-th
index. (to ensure there are no duplicates present)If sum < 0, meaning the 3 numbers are in the negative zone and we increment
j-th
index.If sum > 0, meaning the 3 numbers are in positive territory and we decrement
k-th
index.
We should carry out step 2 with
j < k
condition, until we exhaust all the options in the array by fixing thei-th
index.We then return the result array with triplets without any duplicates in it.
Solution:
class Solution {
public List<List<Integer>> threeSum(int[] nums) {
List<List<Integer>> result = new ArrayList<>();
int len = nums.length;
// Sorting the array to ensure we use the two pointers approach
Arrays.sort(nums);
for(int i=0;i<len-2;i++) {
// For the first number or case (must not contain duplicate triplets)
if(i==0 || nums[i] != nums[i-1]) {
int j = i + 1, k = len - 1;
// Looping here coz we might find another triplet with same 'i'
while(j < k) {
int sum = nums[i] + nums[j] + nums[k];
if(sum == 0) {
result.add(Arrays.asList(nums[i], nums[j], nums[k]));
// must not contain duplicate triplets
while(j < k && nums[j] == nums[j + 1]) j++;
// must not contain duplicate triplets
while(j < k && nums[k] == nums[k - 1]) k--;
j++;
k--;
} else if(sum < 0){
j++;
} else {
k--;
}
}
}
}
return result;
}
}
Next problem:
In the next post, I will cover the below problem.