Skip to content
This repository has been archived by the owner on Oct 1, 2021. It is now read-only.

New python program #407

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
4d0361f
Largest Sum Contiguous Subarray in c++
saurass Oct 18, 2019
71349da
Create caluclate_bill.go
niranjanreddy400 Oct 18, 2019
501683a
create person.go
niranjanreddy400 Oct 18, 2019
4e253f4
Merge pull request #44 from saurass/master
Harshsngh07 Sep 25, 2020
f61bef4
Merge pull request #46 from niranjanreddy400/add_go_file
Harshsngh07 Sep 25, 2020
cb46460
Create JumpGame 2.cpp
harshsngh109 Sep 25, 2020
ee6614d
Merge pull request #196 from harshsngh109/patch-1
Harshsngh07 Sep 25, 2020
f5eab61
Added Fatorial.cs
HenriqueFQuick Sep 27, 2020
b4c5927
Merge pull request #197 from HenriqueFQuick/AddingFiles
Harshsngh07 Sep 27, 2020
27e8acb
changed folder structure
Harshsngh07 Sep 28, 2020
a69329c
Added IsPrime C#
justinushermawan Sep 29, 2020
7c5ff31
Language-translator
AM1CODES Sep 29, 2020
ecdf121
Merge pull request #199 from AM1CODES/newuser1
Harshsngh07 Sep 29, 2020
ef8d290
Merge pull request #198 from justinushermawan/master
Harshsngh07 Sep 29, 2020
830edd1
Add a Python program to Shorten URL
Amitava123 Sep 30, 2020
07bee2e
Merge pull request #200 from Amitava123/amitava-patch-1
Harshsngh07 Sep 30, 2020
457f46c
Update README.md
Harshsngh07 Sep 30, 2020
8d2fb12
Update README.md
Harshsngh07 Sep 30, 2020
399fde1
added base convertor number system python program
prithvirajbytes Sep 30, 2020
269b962
Merge pull request #202 from prithvirajbytes/prithviraj
Harshsngh07 Sep 30, 2020
b47ccac
Added topsort.cpp
suraj0223 Sep 30, 2020
414975f
Create codeql-analysis.yml
Harshsngh07 Sep 30, 2020
6d57f77
Create CelebrityProblem.cpp
harshsngh109 Oct 1, 2020
ca0187b
Create EquilibriumPoint.cpp
harshsngh109 Oct 1, 2020
89fed07
Merge pull request #223 from harshsngh109/master
Harshsngh07 Oct 1, 2020
48d60ad
Create LeadersInArray.cpp
harshsngh109 Oct 1, 2020
2db9836
Merge pull request #224 from harshsngh109/master
Harshsngh07 Oct 1, 2020
5343b7c
Update README.md
Harshsngh07 Oct 1, 2020
0f1cf27
Merge pull request #209 from suraj0223/patch1
Harshsngh07 Oct 7, 2020
289087b
switch to dark mode in JS
mahimasawant Oct 8, 2020
571926b
Merge pull request #229 from mahimasawant/master
Harshsngh07 Oct 8, 2020
cd81034
Create sieve.cpp
Nandini2901 Oct 10, 2020
142f31b
Merge pull request #249 from Nandini2901/Nandini2901-patch-1
Harshsngh07 Oct 11, 2020
a01733d
Added py files.
makshat01 Oct 12, 2020
817396e
Merge pull request #254 from makshat01/hungerpy
Harshsngh07 Oct 12, 2020
3c2d69c
Delete codeql-analysis.yml
Harshsngh07 Oct 15, 2020
9816f7f
Add files via upload
charan-web Oct 16, 2020
1314b04
Merge pull request #299 from charan-web/master
Harshsngh07 Oct 16, 2020
130b72e
pyhton code to send a mail
ani-thanvi Oct 18, 2020
54d4b16
added some Array programs.
nikeight Oct 18, 2020
3322dc1
Merge pull request #330 from Niket-Jain/Array_Programs
Harshsngh07 Oct 18, 2020
14d4e7c
Merge pull request #318 from ani-thanvi/contri-python
Harshsngh07 Oct 19, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"python.pythonPath": "C:\\Users\\deepa\\envs\\conda\\Scripts\\python.exe"
}
15 changes: 15 additions & 0 deletions Language/C#/Fatorial.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@

// C# program for Fatorial
using System;
public class Fatorial
{
public static void Main(string[] args)
{
Console.Write("Enter the factorial you want to find: ");
Console.WriteLine(Fat(int.Parse(Console.ReadLine())));
}
public static int Fat(int a)
{
return a == 0 ? 1 : a*Fat(a-1);
}
}
26 changes: 26 additions & 0 deletions Language/C#/IsPrime.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// C# program to determine is a prime number or not
using System;

public class IsPrime
{
public static void Main(string[] args)
{
Console.Write("Enter a number you want to find out: ");
Console.WriteLine(IsPrime(Convert.ToInt32(Console.ReadLine())) ? "Yes" : "No");
}

public static bool IsPrime(int x)
{
if (x == 2) return true;
if (x < 2 || x % 2 == 0) return false;
for (int i = 3; i <= Math.Sqrt(x); i += 2)
{
if (x % i == 0)
{
return false;
}
}

return true;
}
}
11 changes: 11 additions & 0 deletions Language/C++/CelebrityProblem.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
int getId(int M[MAX][MAX], int n)
{
int cel = 0;
for (int i = 1; i < n; i++)
if (M[cel][i])
cel = i; //prev cel can't be celebrity
for (int i = 0; i < n; i++)
if ((cel != i) && (M[cel][i] || !M[i][cel]))
return -1;
return cel;
}
22 changes: 22 additions & 0 deletions Language/C++/EquilibriumPoint.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
int equilibriumPoint(long long a[], int n)
{
int sum = 0; // initialize sum of whole array
int leftsum = 0; // initialize leftsum

/* Find sum of the whole array */
for (int i = 0; i < n; ++i)
sum += a[i];

for (int i = 0; i < n; ++i)
{
sum -= a[i]; // sum is now right sum for index i

if (leftsum == sum)
return i+1;

leftsum += a[i];
}

/* If no equilibrium index found, then return 0 */
return -1;
}
48 changes: 48 additions & 0 deletions Language/C++/JumpGame 2.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
//O(n)
class Solution
{
public:
int jump(vector<int> &nums)
{
int n = nums.size();
int pos(0), reach(0), jumps(0);

for (int i = 0; i < n - 1; i++)
{
reach = max(reach, i + nums[i]);
if (pos == i)
{
pos = reach;
jumps++;
}
}

return jumps;
}
};

//O(n^2)
class Solution
{
public:
int jump(vector<int> &nums)
{
int n = nums.size();
int dp[n];
memset(dp, 0, sizeof(dp));
dp[0] = 0;
for (int i = 1; i < n; i++)
{
int minV = INT_MAX;
for (int j = 0; j < i; j++)
if (j + nums[j] >= i)
minV = min(minV, dp[j]);
if (minV != INT_MAX)
dp[i] = minV + 1;
else
dp[i] = INT_MAX;
}

return dp[n - 1];
}
};
48 changes: 48 additions & 0 deletions Language/C++/LargestSumContiguousSubarray.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
// C++ program to print largest contiguous array sum

#include<iostream>
#include<climits>
using namespace std;

int maxSubArraySum(int a[], int size)
{
int max_so_far = INT_MIN, max_ending_here = 0,
start =0, end = 0, s=0;

for (int i=0; i< size; i++ )
{
max_ending_here += a[i];

if (max_so_far < max_ending_here)
{
max_so_far = max_ending_here;
start = s;
end = i;
}

if (max_ending_here < 0)
{
max_ending_here = 0;
s = i + 1;
}
}
cout << "Maximum contiguous sum is "
<< max_so_far << endl;
cout << "Starting index "<< start
<< endl << "Ending index "<< end << endl;
}

int main()
{
int n;
cout << "Enter number of elements in array \n";
cin >> n;

int a[n];
for(int i = 0; i < n; i++) {
cout << "Enter element " << i + 1 << " -\n";
cin >> a[i];
}
int max_sum = maxSubArraySum(a, n);
return 0;
}
39 changes: 39 additions & 0 deletions Language/C++/LeadersInArray.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#include<bits/stdc++.h>
using namespace std;

int main()
{
int t;
cin >> t;
while(t--)
{
long long int n;
cin >> n;
long long int a[n];
for(int i=0;i<n;i++)
cin >> a[i];

vector<int> v;

int maxV = INT_MIN;
for(int i=n-1;i>=0;i--)
{

if(a[i]>=maxV)
{
maxV = a[i];
v.push_back(maxV);
}
}

reverse(v.begin(),v.end());
//maxV = a[n-1];
//v.push_back(maxV);


for(int i=0;i<v.size();i++)
cout<< v[i] << " ";
cout<<endl;
}
return 0;
}
34 changes: 34 additions & 0 deletions Language/C++/sieve.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
//Printing the prime numbers upto a given number 'n' in O(n log log n) time.
// as it takes O(n) time in iterartive method.
#include <iostream>
#include <string.h>
using namespace std;
int main()
{
int n;
cin >> n;
int arr[n + 1];
memset(arr, 0, sizeof(arr));
arr[0] = 1;
arr[1] = 1;
for (int i = 2; i <= n; i++)
{
if (arr[i] == 0)
{
for (int j = 2; j <= n / i; j++)
{
if (arr[i * j] != 1)
{
arr[i * j] = 1;
}
}
}
}
for (int i = 0; i <= n; i++)
{
if (arr[i] == 0)
{
cout << i << " ";
}
}
}
96 changes: 96 additions & 0 deletions Language/C++/topsort.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
#include<bits/stdc++.h>
#define Graph unordered_map<int, vector<int>>
#define vi vector<int>
#define vb vector<bool>
using namespace std;
// Top sort is implemented whenever there is no cycle in DAG

bool dfs (int curr, vb visited, Graph graph) {
if(!visited[curr]){

visited[curr] = true;
for(int i=0; i < graph[curr].size(); i++)
return dfs(graph[curr][i], visited, graph);

} else
return true;
}

bool detectCycle(int edges, Graph graph) {

// initialises a visited array of type bool
vb visited(edges, false);

for(auto it : graph) {

visited[it.first] = true;
int sz = it.second.size();

for(int i=0; i<sz; i++) {
// do dfs and check for visited is once againg visiting or not
if(dfs( it.second[i], visited, graph))
return true;
}
visited[it.first] = false;
}
// dfs checked for all vertices and there we found no Cycle
return false;
}

void topSortWithDfs(int curr, vector<int> &result , Graph graph, vb &visitedarray){

if(!visitedarray[curr]) {
visitedarray[curr]=true;

for(int i=0; i<graph[curr].size(); i++)
if(!visitedarray[graph[curr][i]])
topSortWithDfs(graph[curr][i], result, graph, visitedarray);

result.push_back(curr);
}
}

vi topologicalsort(int edges, Graph graph) {

if(detectCycle(edges, graph)) {
cout<< "Oops there is cycle in graph.";
return {};
}


vector<int> result;
vb visitedarray(edges, false);

for(auto item : graph)
topSortWithDfs(item.first, result, graph, visitedarray);

reverse(result.begin(), result.end());
return result;
}


int main() {

Graph graph;
std::cout << "Enter total number of edges : " << '\n';
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);

int edges;
cin>>edges;

// Graph input from user
int tempedges = edges;
while(tempedges--) {
int x;
int y;
cin >> x >> y;
graph[x].push_back(y);
}


for( auto x : topologicalsort(edges, graph))
cout<< x << " ";

return 0;
}
File renamed without changes.
15 changes: 15 additions & 0 deletions Language/Go/caluclate_bill.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package main

import (
"fmt"
)

func calculateBill(price, no int) int {
var totalPrice = price * no
return totalPrice
}
func main() {
price, no := 90, 6
totalPrice := calculateBill(price, no)
fmt.Println("Total price is", totalPrice)
}
Loading