π©βπ» This repository is for Competitive Coders to get started with Open-source.
π We have curated a list of standard problems for you to get better at DSA.
πΎ Follow these steps to get started
π Pick a question from the list given below.
π Fork this repository.
π Add your solution.
π Create pull-request.
π Start contributing to this repository by adding your solutions for questions given below.
During the Induction program at JEC, Chef began liking a girl and wants to look at her. They are sitting in an Auditorium and you are friends with Chef. You have to place a mirror (point size) on the front wall of the hall so that Chef can have a glimpse of her. Consider the front wall as the x-axis. You are given the coordinates of the position of Chef and his Crush (x1,y1), (x2,y2) respectively. Find the position where the mirror should be placed.
Input:
The first line contains the number of test cases T.
The next T lines will have two lines:
Line one contains the coordinates of Chef.
Line two contains the coordinates of Chefβs crush.
Output:
T lines each giving the correct x-coordinate of the mirror up to two decimal places.
Sample input:
1
1 1
4 4
Sample output:
1.60
Constraints:
-109 <= x1,x2 <= 109
0 < y1, y1 <= 109
Given an integer array nums , find the contiguous subarray (containing at least one number) which has the largest sum and return its sum.
A subarray is a contiguous part of an array.
Input: nums = [-2,1,-3,4,-1,2,1,-5,4]
Output: 6
Explanation: [4,-1,2,1] has the largest sum = 6.
Constraints :
1 <= nums.length <= 105
-10 4 <= nums[i] <= 104
Given an array arr[] of non-negative integers representing the height of blocks. If width of each block is 1, compute how much water can be trapped between the blocks during the rainy season.
Input: arr[] = [0,1,0,2,1,0,1,3,2,1,2,1]
Output: 6
Explanation:
The above elevation map (black section) is represented by array [0,1,0,2,1,0,1,3,2,1,2,1]. In this case, 6 units of rain water (blue section) are being trapped.
Constraints :
1 <= nums.length <= 105
-10 4 <= nums[i] <= 104
Given the heads of two singly linked-lists headA and headB, return the node at which the two lists intersect. If the two linked lists have no intersection at all, return null.
Input: LinkedList1 = 3->6->9->common
LinkedList2 = 10->common
Common = 15->30->NULL
Output: 15
Explanation:
Following two linked lists begin to intersect at node 15.
Constraints :
1 β€ N + M β€ 2*105
-1000 β€ value β€ 1000
Given the root of a binary tree, return the zigzag level order traversal of its nodes' values. (i.e., from left to right, then right to left for the next level and alternate between).
Input: root = [3,9,20,null,null,15,7]
Output: [ [3], [20,9], [15,7] ]
Explanation:
Following two linked lists begin to intersect at node 15.
Constraints :
1 β€ N + M β€ 2*105
-1000 β€ value β€ 1000