Git Product home page Git Product logo

dsa's Introduction

Hello, Problem Solvers !!!

πŸ’₯ What it's about?

πŸ‘©β€πŸ’» 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.


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:
-109 <= x1,x2 <= 109
0 < y1, y1 <= 109


Q2. Maximum Subarray

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
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<n;i++){
current_sum+=nums[i];
if(current_sum > max_sum)
max_sum = current_sum;
if(current_sum < 0)
current_sum=0;
}
cout<<max_sum<<endl;
return 0;
}


Q3. Trapping Rainwater

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
Rain Water Trapping
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


Q4. Intersection of Two Linked Lists

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
Intersection of two linked lists
Explanation:
Following two linked lists begin to intersect at node 15.
Constraints :
1 ≀ N + M ≀ 2*105
-1000 ≀ value ≀ 1000


Q5. Zig-Zag traversal of binary tree

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] ]
Zigzag traversal of binary tree
Explanation:
Following two linked lists begin to intersect at node 15.
Constraints :
1 ≀ N + M ≀ 2*105
-1000 ≀ value ≀ 1000


dsa's People

Contributors

shubhamsth9 avatar acmjec avatar 001priyanshu avatar rachitjain-learner avatar ra-jkunwar avatar riteshaldak1302 avatar eroticops avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.