Very rarely do I complete reading a book and this book I did complete, so wanted to ensure I get the most out of it by documenting the important learnings.
My personal opinion, the book is great. Not just to inspire you to earn more money but for life in general. Even if you have no intentions of making money, the book provides a nice perspective to life. And how things around us run. Be it education, our 9 to 5 job, just living life to its fullest. This book has apt summaries after each chapter which is great when…
Every now and then you will hear developers talk about embracing immutability but what’s the real deal with it.
This article is inspired by Venkat Subramaniam’s Voxxed Days Talk. It was very well executed and here are my notes from it.
Opposite of mutability and that means modifying the state (content) of an object, whether primitive or object. And yes, we do do this very often. So what’s wrong? Let’s consider the following:
This interface has a method that returns void, and has no arguments. What this means is that the Implementer class of this interface will have to…
Given a positive integer
num, output its complement number. The complement strategy is to flip the bits of its binary representation.
Please try on your own before reading on.
Before solving this problem, we need to understand a few concepts in bitwise manipulation.
5 → 101
Complement of 5 → 010
And 101 ^ 010 = 111
A ^ B = C
A ^ A ^ B = A ^ C
0 ^ B = A ^ C
B is the complement of A in this case and that is what we want to achieve.
Below are some problems I have experienced at work (mostly working on large enterprise systems). I have attempted to describe and share some of the ways my team tried to overcome these issues.
“Why the hell did we do this, this way??”
Example: Have you seen some portion of code in your code-base where there is an obvious easy and simple way to implement something but you see that it’s implemented in a somewhat complicated manner. It’s probably because at some point that was the only viable option for the developer. …
Minimum number of cuts to ensure every sub string is a palindrome.
Please try on your own before reading on.
We will try to get to the solution via…
So at minCuts, the value at minCuts refers to the minimum number of cuts to form palindromes for the string “bana” and in this case it is: 1 (after ‘b’). So minCuts[length -1] refers to the minimum cuts to form palindromes for “banana”.
minCuts: “b” : 0 : ‘b’ is a palindrome in itself so zero cuts.
minCuts: “ba” : 1 : “ba”…
Given a sequence of n integers a1, a2, …, an, a 132 pattern is a subsequence ai, aj, ak such that i < j < k and ai < ak < aj. Design an algorithm that takes a list of n numbers as input and checks whether there is a 132 pattern in the list.
Note: n will be less than 15,000.
Input: [1, 2, 3, 4]Output: FalseExplanation: There is no 132 pattern in the sequence.
Input: [3, 1, 4, 2]Output: TrueExplanation: There is a 132 pattern in the sequence: [1, 4…
This is another one from LeetCode: https://leetcode.com/problems/word-break-ii/
Given a non-empty string s and a dictionary wordDict containing a list of non-empty words, add spaces in s to construct a sentence where each word is a valid dictionary word. Return all such possible sentences.
s = "catsanddog"
wordDict = ["cat", "cats", "and", "sand", "dog"]
"cats and dog",
"cat sand dog"
Please give this question a try before reading further.
“catsanddog” → “catsand”…
Two players take turns drawing from a common pool of numbers of 1..15 without replacement until they reach a total ≥ 100.
Given an integer
maxChoosableInt and another integer
desiredTotal, determine if the first player to move can force a win, assuming both players play optimally.
You can always assume that
maxChoosableInt will not be larger than 20 and
desiredTotal will not be larger than 300. Below is an example explanation.
Input: maxChoosableInteger = 10 desiredTotal = 11 Output: false Explanation: No matter which integer the first player choose, the first player will lose. The first player can choose an…
This is Part 1 of more articles to come, where I have documented the steps I took to create a Spring Boot server which exposes a GraphQL endpoint.
I will be starting from the basics and moving on to make the application more advanced.
This example uses Apache Maven. Below is the POM file. All the versions of the different dependencies needed to compile and run the example are listed below. I have used the latest versions of the dependencies available at the point of writing this article.
<groupId>com.saloni</groupId> <artifactId>graphqlguide</artifactId> <version>1.0-SNAPSHOT</version> <parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>2.1.3.RELEASE</version> <relativePath/> </parent> <properties> <java.version>1.9</java.version> <graphql-spring-boot-starter.version>5.0.2</graphql-spring-boot-starter.version>…
I can code and stuff.