life is too short for a diary



Posts Tagged “java”

2 min read

Leetcode - All Divisions With the Highest Score of a Binary Array

You are given a 0-indexed binary array nums of length n. nums can be divided at index i (where 0 <= i <= n) into two arrays (possibly empty) numsleft and numsright..


Continue reading → leetcode hashmap array java python



1 min read

Course Schedule Leetcode Solution

There are a total of numCourses courses you have to take, labeled from 0 to numCourses - 1. You are given an array prerequisites where prerequisites[i] = [ai, bi] indicates that you must take course bi first if you want to take course ai...


Continue reading → leetcode graph bfs java python



1 min read

Remove-all-adjacent-duplicates-in-string-ii Solution

You are given a string s and an integer k, a k duplicate removal consists of choosing k adjacent and equal letters from s and removing them, causing the left and the right side of the deleted substring to concatenate together...


Continue reading → leetcode stack python java scala javascript



2 min read

Lowest Common Ancestor of a Binary Tree

Questions involving the binary tree data structure are very popular in tech interviews, and can be challenging and varied! A binary tree is a data structure consisting of a collection of nodes (starting at a root node), where each node consists of a value (data), together with a directed edges to at most two nodes (the “left child” and “right child”), with the additional conditions that no two edges point to the same node and no edge points to the root. I recently solved an interesting problem on binary tree...


Continue reading → leetcode java python javascript scala



1 min read

Ternary String solution Codeforces - 1354B

Ternary string is an interesting problem that could be solved using two pointers techniques. It’s a convenient way to keep track of multiple indices. This helps in making decisions based on two values...


Continue reading → codeforces two pointers java python



2 min read

Coin Change solution leetcode

It’s one of the most popular questions on leetcode that seems very easy at first. Coin change is a classic dynamic programming problem. I will proceed with an obvious (albeit wrong) solution and subsequently proceed to an efficient correct solution...


Continue reading → leetcode dp java python



1 min read

Maximum Subarray

There’s an interesting problem I recently solved on leetcode based on dynamic programming. My Github repository contains list of all problems that I have solved. I often start with a brute force approach without fretting about time complexity. Later I try to improve my algorithm for a better efficient solution...


Continue reading → leetcode dp java python



5 min read

Getting started with Graph Part 1

Graph are data structures made of vertices & edges. There are lots of interesting problems that can be solved using graphs. Part 1 covers the basic for creating a template for graph data structure...


Continue reading → graph java implementation



4 min read

Recursively sort a array

I recently came across a simple telephonic interview problem. The problem was to sort an array recursively. But even numbers need to be placed before odd numbers. At first glance it was obvious that it was a simple case of implementation of merge sort...


Continue reading → programming interview merge sort sort java code



1 min read

Three Sum Problem Leetcode Solution

Given an array nums of n integers, are there elements a, b, c in nums such that a + b + c = 0? Find all unique triplets in the array which gives the sum of zero...


Continue reading → leetcode two pointers java