# Hello, Problem Solvers !!!

💥
What it's about?

#### Q1. Positioning of Mirror

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:**

-10^{9} <= x1,x2 <= 10^{9}

0 < y1, y1 <= 10^{9}

#### Given an integer array nums , find the contiguous subarray (containing at least one number) which has the largest sum and return its sum. Q2. Maximum Subarray

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 <= 10^{5}

-10 ^{4} <= nums[i] <= 10^{4}

**Solution** We will initiate two variables current_sum and max_sum initiated with zero, then iterate over array to add every element to current_sum and compare with max_sum if current sum becomes greater than max_sum it will assign max_sum the value of current_sum . And in case current_sum becomes negative we will reinitialize it with zero. **Code** In C++ :

#include

using namespace std;

int main(){

int n;

cin>>n;

int nums[n];

for(int i = 0;i < n;i++){

cin>>nums[i];

}

int current_sum=0,max_sum=0;

for(int i=0;i

current_sum+=nums[i];

if(current_sum > max_sum)

max_sum = current_sum;

if(current_sum < 0)

current_sum=0;

}

cout<

return 0;

}

#### 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. Q3. Trapping Rainwater

**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 <= 10^{5}

-10 ^{4} <= nums[i] <= 10^{4}

#### 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. Q4. Intersection of Two Linked Lists

**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*10^{5}

-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). Q5. Zig-Zag traversal of binary tree

**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*10^{5}

-1000 ≤ value ≤ 1000