Giter Club home page Giter Club logo

python-cpp-html-programs-projects's People

Contributors

abhaysharmaa23 avatar ajay-007-e avatar amanpandey2101 avatar armankumar21 avatar aseemsahoo avatar botketan avatar dhaneshragu avatar krishchopra22 avatar lakshgujarati avatar madscientist46290 avatar prabir227 avatar puneethkshetty avatar rajnandanprasad avatar sakshi2002-sinha avatar samkitjain4916 avatar shreyash1601 avatar sougata2 avatar subham2409 avatar subratyeeshu avatar sudheerdagar avatar suraj-s13 avatar swapnil05rai avatar theyashwanthsai avatar ut03 avatar vavy06 avatar vbhvshukla avatar viz38 avatar vrup0408 avatar yashbajoria05 avatar yatish6360 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

python-cpp-html-programs-projects's Issues

Minimize the Heights II (python or cpp only)

Given an array arr[] denoting heights of N towers and a positive integer K.

For each tower, you must perform exactly one of the following operations exactly once.

Increase the height of the tower by K
Decrease the height of the tower by K
Find out the minimum possible difference between the height of the shortest and tallest towers after you have modified each tower.

You can find a slight modification of the problem here.
Note: It is compulsory to increase or decrease the height by K for each tower. After the operation, the resultant array should not contain any negative integers.

Example 1:
Input:
K = 2, N = 4
Arr[ ] = {1, 5, 8, 10}
Output:
5

Explanation:
The array can be modified as
{3, 3, 6, 8}. The difference between
the largest and the smallest is 8-3 = 5.

Regular Expression Matching(Python or cpp)

Given an input string s and a pattern p, implement regular expression matching with support for '.' and '*' where:

  • '.' Matches any single character.​​​​
  • '*' Matches zero or more of the preceding element.
    The matching should cover the entire input string (not partial).

Example 1:

Input: s = "aa", p = "a"
Output: false
Explanation: "a" does not match the entire string "aa".

Example 2:

Input: s = "aa", p = "a*"
Output: true
Explanation: '*' means zero or more of the preceding element, 'a'. Therefore, by repeating 'a' once, it becomes "aa".

Single Number using python or cpp

Given a non-empty array of integers nums, every element appears twice except for one. Find that single one.

You must implement a solution with a linear runtime complexity and use only constant extra space.

Example 1:

Input: nums = [2,2,1]
Output: 1
Example 2:

Input: nums = [4,1,2,1,2]
Output: 4
Example 3:

Input: nums = [1]
Output: 1

Overlapping Intervals(using python or cpp only)

Given a collection of Intervals, the task is to merge all of the overlapping Intervals.

Example 1:

Input:
Intervals = {{1,3},{2,4},{6,8},{9,10}}
Output: {{1, 4}, {6, 8}, {9, 10}}
Explanation: Given intervals: [1,3],[2,4] ,[6,8],[9,10], we have only two overlapping intervals here,[1,3] and [2,4]. Therefore
we will merge these two and return [1,4],[6,8], [9,10].

Example 2:

Input:
Intervals = {{6,8},{1,9},{2,4},{4,7}}
Output: {{1, 9}}

Heap Sort

Given an array of size N. The task is to sort the array elements by completing functions heapify() and buildHeap() which are used to implement Heap Sort.

Example 1:

Input:
N = 5
arr[ ] = {4,1,3,9,7}
Output:
1 3 4 7 9
Explanation:
After sorting elements using heap sort, elements will be in order as 1,3,4,7,9.

Example 2:

Input:
N = 10
arr[ ] = {10,9,8,7,6,5,4,3,2,1}

Output:
1 2 3 4 5 6 7 8 9 10
Explanation:
After sorting elements using heap sort, elements will be in order as 1, 2,3,4,5,6,7,8,9,10.

Find Missing And Repeating

Given an unsorted array Arr of size N of positive integers. One number 'A' from set {1, 2,....,N} is missing and one number 'B' occurs twice in array. Find these two numbers.

Alphabet Rangoli (python or cpp only)

You are given an integer, . Your task is to print an alphabet rangoli of size . (Rangoli is a form of Indian folk art based on creation of patterns.)

Different sizes of alphabet rangoli are shown below:

#size 3

----c----
--c-b-c--
c-b-a-b-c
--c-b-c--
----c----

#size 5

--------e--------
------e-d-e------
----e-d-c-d-e----
--e-d-c-b-c-d-e--
e-d-c-b-a-b-c-d-e
--e-d-c-b-c-d-e--
----e-d-c-d-e----
------e-d-e------
--------e--------

#size 10

------------------j------------------
----------------j-i-j----------------
--------------j-i-h-i-j--------------
------------j-i-h-g-h-i-j------------
----------j-i-h-g-f-g-h-i-j----------
--------j-i-h-g-f-e-f-g-h-i-j--------
------j-i-h-g-f-e-d-e-f-g-h-i-j------
----j-i-h-g-f-e-d-c-d-e-f-g-h-i-j----
--j-i-h-g-f-e-d-c-b-c-d-e-f-g-h-i-j--
j-i-h-g-f-e-d-c-b-a-b-c-d-e-f-g-h-i-j
--j-i-h-g-f-e-d-c-b-c-d-e-f-g-h-i-j--
----j-i-h-g-f-e-d-c-d-e-f-g-h-i-j----
------j-i-h-g-f-e-d-e-f-g-h-i-j------
--------j-i-h-g-f-e-f-g-h-i-j--------
----------j-i-h-g-f-g-h-i-j----------
------------j-i-h-g-h-i-j------------
--------------j-i-h-i-j--------------
----------------j-i-j----------------
------------------j------------------
The center of the rangoli has the first alphabet letter a, and the boundary has the alphabet letter (in alphabetical order).

Function Description

Complete the rangoli function in the editor below.

rangoli has the following parameters:

int size: the size of the rangoli
Returns

string: a single string made up of each of the lines of the rangoli separated by a newline character (\n)
Input Format

Only one line of input containing , the size of the rangoli.

Constraints:
0<size<27

Arithmetic Number

Given three integers 'A' denoting the first term of an arithmetic sequence , 'C' denoting the common difference of an arithmetic sequence and an integer 'B'. you need to tell whether 'B' exists in the arithmetic sequence or not.

Example 1:

Input: A = 1, B = 3, C = 2
Output: 1
Explaination: 3 is the second term of the sequence starting with 1 and having a common
difference 2.

Example 2:

Input: A = 1, B = 2, C = 3
Output: 0
Explaination: 2 is not present in the sequence.

Your Task:
You do not need to read input or print anything. Your task is to complete the function inSequence() which takes A, B and C and returns 1 if B is present in the sequence. Otherwise, returns 0.

Expected Time Complexity: O(1)
Expected Auxiliary Space: O(1)

Constraints:
-109 ≤ A, B, C ≤ 109

Search in a Rotated Array(python or cpp only)

Given a sorted and rotated array A of N distinct elements which is rotated at some point, and given an element key. The task is to find the index of the given element key in the array A.

Example 1:

Input:
N = 9
A[ ] = {5, 6, 7, 8, 9, 10, 1, 2, 3}
key = 10
Output: 5
Explanation: 10 is found at index 5.

Example 2:

Input:
N = 4
A[ ] = {3, 5, 1, 2}
key = 6
Output: -1
Explanation: There is no element that has value 6.

Spirally traversing a matrix (python or cpp only)

Given a matrix of size r*c. Traverse the matrix in spiral form.

Example 1:

Input:
r = 4, c = 4
matrix[][] = {{1, 2, 3, 4},
{5, 6, 7, 8},
{9, 10, 11, 12},
{13, 14, 15,16}}
Output:
1 2 3 4 8 12 16 15 14 13 9 5 6 7 11 10

Merge two BST 's (pyhton,cpp or java)

Given two BSTs, return elements of both BSTs in sorted form.

Example 1:

Input:
BST1:
5
/
3 6
/
2 4
BST2:
2
/
1 3

7
/
6
Output: 1 2 2 3 3 4 5 6 6 7
Explanation:
After merging and sorting the two BST we get 1 2 2 3 3 4 5 6 6 7.

Example 2:

Input:
BST1:
12
/
9
/ \
6 11
BST2:
8
/
5 10
/
2
Output: 2 5 6 8 9 10 11 12
Explanation:
After merging and sorting the two BST we get 2 5 6 8 9 10 11 12.

Median of Two Sorted Arrays (cpp or python)

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)).

Input: nums1 = [1,3], nums2 = [2]
Output: 2.00000
Explanation: merged array = [1,2,3] and median is 2.

@anomekumar08 Please assign it to me under HF22

Sort an array of 0s, 1s and 2s

Hey!..Help me with thia issue..You can solve this issue with python or cpp.
Given an array of size N containing only 0s, 1s, and 2s; sort the array in ascending order.

Example 1:

Input:
N = 5
arr[]= {0 2 1 2 0}
Output:
0 0 1 2 2
Explanation:
0s 1s and 2s are segregated
into ascending order.
Example 2:

Input:
N = 3
arr[] = {0 1 0}
Output:
0 0 1
Explanation:
0s 1s and 2s are segregated
into ascending order.

Your Task:
You don't need to read input or print anything. Your task is to complete the function sort012() that takes an array arr and N as input parameters and sorts the array in-place.

Expected Time Complexity: O(N)
Expected Auxiliary Space: O(1)

Maximum subset XOR(python , cpp and java only)

Given an array arr[] of N positive integers. Find an integer denoting the maximum XOR subset value in the given array arr[].

Example 1:

Input :
N = 3
arr[ ] = {2, 4, 5}
Output : 7
Explanation : The subset {2, 5} has maximum subset XOR value.

Example 2 :

Input :
N= 3
arr[ ] = {9, 8, 5}
Output : 13
Explanation : The subset {8, 5} has maximum subset XOR value.

3Sum (cpp or python)

Given an integer array nums, return all the triplets [nums[i], nums[j], nums[k]] such that i != j, i != k, and j != k, and nums[i] + nums[j] + nums[k] == 0.

Notice that the solution set must not contain duplicate triplets.

Input: nums = [-1,0,1,2,-1,-4]
Output: [[-1,-1,2],[-1,0,1]]
Explanation:
nums[0] + nums[1] + nums[2] = (-1) + 0 + 1 = 0.
nums[1] + nums[2] + nums[4] = 0 + 1 + (-1) = 0.
nums[0] + nums[3] + nums[4] = (-1) + 2 + (-1) = 0.
The distinct triplets are [-1,0,1] and [-1,-1,2].
Notice that the order of the output and the order of the triplets does not matter.

@anomekumar08 Please assign issue under hacktoberfest2022

Detect cycle in a linked list.

Given a linked list such that it's edges are numbered as a1, a2, .... an.
The linked list is as follows.
image
Then detect if there is a cycle in the linked list or not.

Expected time complexity ; O(n)
Expected space complexity: O(1).

@anomekumar08 please assign this issue to me under Hacktoberfest 22.

Mirko at construction site (python,cpp,java)

Mirko is monitoring a construction site. He monitors buildings enumerated from to , starting from the left. For each building, he knows the current number of floors and the number of floors built on each day. He needs to know the answer to queries. The answer to each query is the index of the tallest building after days, as defined by the query. Your task is to help Mirko find the answers to these queries.

Input Format

The first line consists of the numbers and . The second line consists of integers, where the integer represents the initial height of the building. The third line consists of integers, where the integer represents the number of floors erected in one day for the building. The following lines consist of the integer, , representing the day in the query.

Output Format

For each query, output one number which represents the index of the tallest building after days. If there is more than one building, output the building with the greatest index in the input array (with indexes starting at 1).

Constraints:
-> 1<= N<= 10^5
-> 1<= Q<= 10^5

Every other integer in the input will fit in a 32-bit signed integer. And they will be non-negative integers.
Sample Input

3 6
7 5 1
1 2 3
0
1
2
3
4
5
Sample Output

1
1
2
2
3
3

BotClean Stochastic (Any language)

A deterministic environment is one where the next state is completely determined by the current state of the environment and the task executed by the agent. If there is any randomness involved in determining the next state, the environment is stochastic.

The game Bot Clean took place in a deterministic environment. In this version, the bot is given 200 moves to clean as many dirty cells as possible. The grid initially has 1 dirty cell. When the bot cleans this cell, a new cell in the grid is made dirty. The new cell can be anywhere in the grid.

The bot here is positioned at the top left corner of a 5*5 grid. Your task is to move the bot to appropriate dirty cell and clean it.

Input Format
The first line contains two single spaced integers which indicates the current position of the bot. The grid is indexed (x, y) 0<=x,y<=4 top to bottom and left to right respectively. Refer to to board convention here.

5 lines follow showing the grid rows. Each cell in the grid is represented by any of the following 3 characters:

'b' (ascii value 98) - the bot's current position (if on clean cell).

'd' (ascii value 100) - a dirty cell (even if the robot is present on top of it).

'-' (ascii value 45) - a clean cell in the grid.

Sample Input

0 0
b---d




Output Format

Output is the action that is taken by the bot in the current step and it can be any of the movements in 4 directions or cleaning the cell in which it is currently located. The output formats are LEFT, RIGHT, UP and DOWN or CLEAN. Output CLEAN to clean the dirty cell. Repeat this process until all the cells on the grid are cleaned.

Sample Output

RIGHT
Resultant State

-b--d




The bot is positioned now at (0,1) and is 1 step closer to the dirty cell. The next input will be

0 1
-b--d




Task

Complete the function nextMove that takes in 3 parameters posr, posc being the co-ordinates of the bot’s current position and board which indicates the board state, and print the bot’s next move.

Scoring

At the end of 200 moves, your score will be equal to the number of dirty cell the bot has cleaned divided by 4.

Boleyn salary (Python or cpp only)

Hey? Everyone... Help me with this problem.

Boleyn Su runs a company called Acme. There are N employees in the company, and each one of them is represented by a unique employee id whose range lies in [1, N]. Being the head of company, Boleyn's employee id is 1.

Each employee, except Boleyn, has exactly one direct superior. This means that the hierarchial structure of the company is like a tree, where

Boleyn, employee id 1, represents the root node.
Each pair of employee is directly or indirectly connected to one another.
There is no cycle.
Let's represent the salary by the array s = {s[1], s[2], s[3]..., s[N]}, where s[i] is the salary of the ith employee. Salary structure in the company is non-uniform. Even a subordinate may get a higher salary than her superior. Some of the employees in Acme are curious about who gets the kth lowest salary among her subordinates. Help them in solving their query.

Note

1st lowest salary is equivalent to lowest salary, 2nd lowest means lowest salary which is greater that 1st lowest salary, and so on.
Salary of each employee is different.
It is not necessary that the people who are placed higher on hierarchy will have a greater salary than their subordinates.
Input Format
The first line contains two space separated integers, N Q, where N is the number of employees in Acme, and Q is the number of queries.
Then follows N-1 lines. Each of these lines contain two space separated integers, u p, where p is the superior of u. u and p are employees id.
In the next line there are N space separated integers, s[1] s[2] ... s[n], where s[i], i ∈ [1..N], is the salary of ith employee.
Then, Q queries follow. Each query contains two space separated integers, v k. See output format for it's definition.

Output format
For the first query, print the id of employee who has the kth lowest salary among the subordinates of v.
For the subsequent queries, we need to find the kth lowest salary of the subordinates of v+d, where d is the answer of previous query.

Constraints
1 ≤ N ≤ 3104
1 ≤ Q ≤ 3
104
1 ≤ s[ i ] ≤ 109, i ∈ [1..N]
s[ i ] ≠ s[ j ], 1 ≤ i < j ≤ N
1 ≤ u, p ≤ N, u ≠ p
-N ≤ d ≤ N
For 1st query, 1 ≤ v ≤ N
For later queries, 1 ≤ v+d ≤ N
For each query, 1 ≤ K ≤ Number_of_subordinates

Sample Input

8 7
2 1
3 2
4 2
7 4
8 4
5 1
6 5
70 40 60 80 10 20 30 50
2 1
-6 5
-4 1
-5 3
2 1
-5 4
2 2
Sample Output

7
8
7
3
6
2
8

Merge Nodes in Between Zeros(python or cpp only)

Hey! Everyone..Please Help me with my today's Leetcode problem.
You are given the head of a linked list, which contains a series of integers separated by 0's. The beginning and end of the linked list will have Node.val == 0.

For every two consecutive 0's, merge all the nodes lying in between them into a single node whose value is the sum of all the merged nodes. The modified list should not contain any 0's.

Return the head of the modified linked list.

Example 1:

Input: head = [0,3,1,0,4,5,2,0]
Output: [4,11]
Explanation:
The above figure represents the given linked list. The modified list contains

  • The sum of the nodes marked in green: 3 + 1 = 4.
  • The sum of the nodes marked in red: 4 + 5 + 2 = 11.

Example 2:

Input: head = [0,1,0,3,0,2,2,0]
Output: [1,3,4]
Explanation:
The above figure represents the given linked list. The modified list contains

  • The sum of the nodes marked in green: 1 = 1.
  • The sum of the nodes marked in red: 3 = 3.
  • The sum of the nodes marked in yellow: 2 + 2 = 4.

Constraints:
The number of nodes in the list is in the range [3, 2 * 10^5].
0 <= Node.val <= 1000
There are no two consecutive nodes with Node.val == 0.
The beginning and end of the linked list have Node.val == 0.

Reverse Nodes in k-Group (python or cpp only)

Given the head of a linked list, reverse the nodes of the list k at a time, and return the modified list.

k is a positive integer and is less than or equal to the length of the linked list. If the number of nodes is not a multiple of k then left-out nodes, in the end, should remain as it is.

You may not alter the values in the list's nodes, only nodes themselves may be changed.

Example
Input: head = [1,2,3,4,5], k = 2
Output: [2,1,4,3,5]

@anomekumar08 Please assign it to me under hacktoberfest2022

Insertion sort

This algorithm sorts a collection by comparing adjacent elements. When it finds that order is not respected, it moves the element compared backward until the order is correct. It then goes back directly to the element's initial position resuming forward comparison.

Sudoko Solver (cpp or python)

Write a program to solve a Sudoku puzzle by filling the empty cells.

A sudoku solution must satisfy all of the following rules:

Each of the digits 1-9 must occur exactly once in each row.
Each of the digits 1-9 must occur exactly once in each column.
Each of the digits 1-9 must occur exactly once in each of the 9 3x3 sub-boxes of the grid.

The '.' character indicates empty cells.

Input: nums = [0,1,1]
Output: []
Explanation: The only possible triplet does not sum up to 0.

@anomekumar08 Please assign it to me under HF22

Zero Sum Subarrays (Python or cpp only)

You are given an array arr[] of size n. Find the total count of sub-arrays having their sum equal to 0.
Example 1:

Input:
n = 6
arr[] = {0,0,5,5,0,0}
Output: 6
Explanation: The 6 subarrays are
[0], [0], [0], [0], [0,0], and [0,0].

Example 2:

Input:
n = 10
arr[ ] = {6,-1,-3,4,-2,2,4,6,-12,-7}
Output: 4
Explanation: The 4 subarrays are [-1 -3 4]
[-2 2], [2 4 6 -12], and [-1 -3 4 -2 2]

Merge Two Sorted Lists

Hey ! Help me with this issue and create Pull request. You can use Python or cpp for this issue.
You are given the heads of two sorted linked lists list1 and list2.

Merge the two lists in a one sorted list. The list should be made by splicing together the nodes of the first two lists.

Return the head of the merged linked list.

Example 1:

Input: list1 = [1,2,4], list2 = [1,3,4]
Output: [1,1,2,3,4,4]

Example 2:

Input: list1 = [], list2 = []
Output: [ ]

Example 3:
Input: list1 = [], list2 = [0]
Output: [0]

Constraints:

The number of nodes in both lists is in the range [0, 50].

-100 <= Node.val <= 100

Both list1 and list2 are sorted in non-decreasing order.

Check two arrays are equal or not

Hey ! Please help me with this issue. You can solve it with python or cpp then you need to make a pull request.

Given two arrays A and B of equal size N, the task is to find if given arrays are equal or not. Two arrays are said to be equal if both of them contain same set of elements, arrangements (or permutation) of elements may be different though.
Note : If there are repetitions, then counts of repeated elements must also be same for two array to be equal.

Example 1:

Input:
N = 5
A[ ] = {1,2,5,4,0}
B[ ] = {2,4,5,0,1}
Output: 1
Explanation: Both the array can be
rearranged to {0,1,2,4,5}
Example 2:

Input:
N = 3
A[ ] = {1,2,5}
B[ ] = {2,4,15}
Output: 0
Explanation: A[] and B[] have only
one common value.

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.