Author: prakashsinghabody@gmail.com

Interview Questions

Can Place Flowers

Problem Statement You have a long flowerbed in which some of the plots are planted, and some are not. However, flowers cannot be planted in adjacent plots. Given an integer array flowerbed containing 0‘s and 1‘s, where 0 means empty and 1 means not empty, and an integer n, return true if n new flowers can be planted in the flowerbed without violating the no-adjacent-flowers rule and false otherwise. Example 1: Input: flowerbed = […]

prakashsinghabody@gmail.com 
Interview Questions

Greatest Common Divisor of Strings

Problem Statement Greatest Common Divisor of Strings For two strings s and t, we say “t divides s” if and only if s = t + t + t + … + t + t (i.e., t is concatenated with itself one or more times). Given two strings str1 and str2, return the largest string x such that x divides both str1 and str2. Example 1: Input: str1 = “ABCABC”, str2 = “ABC” Output: “ABC” […]

prakashsinghabody@gmail.com 
Interview Questions

Primitives

Array Integer Array Operations Comparison Array Operations Comparison Operation Java Go (Golang) Python 3 Array Declaration int[] arr; var arr [size]int arr = [] Array Initialization with Length int[] arr = new int[5]; var arr = make([]int, 5) arr = [None]*5 Array Initialization without Length int[] arr = {1, 2, 3}; arr := []int{1, 2, […]

prakashsinghabody@gmail.com 
Interview Questions

Merge Strings Alternately

LeetCode #1768 Problem statement You are given two strings word1 and word2. Merge the strings by adding letters in alternating order, starting with word1. If a string is longer than the other, append the additional letters onto the end of the merged string. Return the merged string. Example 1: Input: word1 = “abc”, word2 = “pqr” Output: “apbqcr” Explanation: The merged […]

prakashsinghabody@gmail.com 
Interview Questions

Median of Two Sorted Arrays

LeetCode # 4 Problem statement Given two sorted arrays nums1 and nums2 of size m and n respectively, return the median of the two sorted arrays. The overall run time complexity should be O(log (m+n)). Example Example 1: Example 2: JAVA CODE Median of Two Sorted Arrays BRUTE FORCE APPROACH LOGIC Better Approach LOGIC Optimal Solution Logic Complexity Visit https: https://codeandalgo.com for more such contents.

prakashsinghabody@gmail.com 
Interview Questions

Add to Array-Form of Integer

LeetCode Problem #989 Problem Statement The array-form of an integer num is an array representing its digits in left to right order. Given num, the array-form of an integer, and an integer k, return the array-form of the integer num + k. Example 1: Input: num = [1,2,0,0], k = 34Output: [1,2,3,4]Explanation: 1200 + 34 = 1234 LOGIC We have 2 numbers lets say number_1 and number_2. […]

prakashsinghabody@gmail.com 
Interview Questions

Two Sum

LeetCode#1 Problem Statement Given an array of integers nums and an integer target, return indices of the two numbers such that they add up to target. You may assume that each input would have exactly one solution, and you may not use the same element twice. You can return the answer in any order. Golang code for Two sum JAVA CODE TWO SUM Version-1 […]

prakashsinghabody@gmail.com 
Interview Questions

Water Bottles

1518. Water Bottles Problem Statement There are numBottles water bottles that are initially full of water. You can exchange numExchange empty water bottles from the market with one full water bottle. The operation of drinking a full water bottle turns it into an empty bottle. Given the two integers numBottles and numExchange, return the maximum number of water bottles you can drink. JAVA CODE Water […]

prakashsinghabody@gmail.com