This is going to be very short and precise article on how to setup you macbook pro with java and maven.

Now macbook is coming default with zsh shell.

Steps for Java setup:

— — — — — — — — — — — — — — — — — — — — — — — — —

If you are using nano editor:(Basics of nano editor)

  1. nano ~/.zshenv -> It will open the file in nano editor.
  2. Add the content.
  3. Use key combination Ctrl + 0 to save and then press enter.
  4. Use key combination Ctrl + x to…


I came across these two questions and found similarities.

  1. Buy and Sell only 1 time to get maximum profit.
  2. Buy and Sell multiple times to get maximum profit.

Here comes the solutions for the same, The code is the same for both the questions but with minor differences.

Solution 1: Buy and Sell single time:

Input: prices = [7,1,5,3,6,4]
Output: 5
Explanation: Buy on day 2 (price = 1) and sell on day 5 (price = 6), profit = 6-1 = 5. …


This is a good question, So decided to solve it.

Given two sorted arrays, such that the arrays may have some common elements. Find the sum of the maximum sum path to reach from the beginning of any array to end of any of the two arrays. We can switch from one array to another array only at common elements.
Note: The common elements do not have to be at the same indexes.
Expected Time Complexity: O(m+n), where m is the number of elements in ar1[] and n is the number of elements in ar2[].

Examples:

Input: ar1[] = {2…


This is marked as Hard on the geek's platform.

Given an odd integer n, find a matrix of size n x n with the following conditions:

  1. Each cell contains an integer from 1 and n (inclusive).
  2. No integer appears twice in the same row or the same column.
  3. All 1’s must be at every possible distance from the center of the matrix. The center of a n x n square is cell ((n-1)/2, (n-1)/2) for odd n.

Example :


Input : n = 1
Output : 1

Input : n = 3
Output: 3 2 1…


This question is based on ladder and stairs, We need to find the minimum number of jumps to reach the end.

Here we will follow few steps:

  1. initialize stairs and ladder as the first element of the array.
  2. Keep track of the maximum ladder we got as of now.
  3. decrease the stairs as we climb up.
  4. if stairs become zero in the current ladder make a jump to another ladder and recalculate the stairs left in that ladder to reach the top(stairs = ladder level)

Below is the implementation of the code.

class Solution {
public int…


This question is similar to check if two trees are symmetric or not.

https://leetcode.com/problems/subtree-of-another-tree/

Given two non-empty binary trees s and t, check whether tree t has exactly the same structure and node values with a subtree of s. A subtree of s is a tree that consists of a node in s and all of this node’s descendants. The tree s could also be considered as a subtree of itself.

Example 1:
Given tree s:

3
/ \
4 5
/ \
1 2

Given tree t:

4 
/ \
1 2

Return true, because t has the same…


I came across these 2 questions and found a similarity in the logic part.

  1. Symmetric Tree:

We need to check symmetry for the same tree or say mirror image.

Input:
5
/ \
1 1
/ \
2 2
Output:
True
Explanation:
Tree is mirror image of
itself i.e. tree is symmetric

Here comes the solution for the same.

/*
class of the node of the tree is as
class Node{
int data;
Node left;
Node right;
Node(int data){
this.data = data;
left=null;
right=null;
}
}
*/
// complete this function
// return true/false if the is Symmetric or not
class GfG
{…


I came across these 2 questions and found similarities in both of them.

Now, let's discuss the solution:

  1. Check for a balanced tree:
Input:
10
/ \
20 30
/ \
40 60
Output: 1
Explanation:
The max difference in height
of left subtree and right subtree is 1.
Hence balanced.

Here First we need to find the height of the binary tree for both part i.e. left tree and right tree for each node, if the difference between them is greater than 1 then it is not balanced tree, return false.

How to find the height of the binary…


Recently I study the topic and sharing the notes for the same.

Inner Classes

Without existing one type of object if there is no chance of existing another type of object then we should go for inner classes.
Note(we can declare anything inside anything means class inside interface or interface inside the class)
Ex: 1 class Car{
class Engine{}
}
Here without Car object, there is no chance of an Engine object.

Ex: 2 Map Interface: A map is a group of key-value pair and each key-value pair is called an entry, without an existing map object there is no…


I came across this question in an interview recently for the SDE-2 position.

There is a shop with old-style cash registers. the price of each item is typed manually. Given a list of items and their correct prices, compare the prices to those entered when each item was sold. Determine the number of errors in the selling price.

Input:
products = ['eggs','milk','cheese']
productPrices = [2.89,3.29,5.79]
productsSold = ['eggs','eggs','milk','cheese']
sellingPrices = [2.89,2.99,3.29,5.97]
Output: errors = 2

Here Comes the Solution for the same.

Use 2 HashMap, one for Storing the original product name and product price, HashMap<String, Float> map2 = new…

Vipul Gupta

Software Developer

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store