Skip to content

Commit

Permalink
Merge branch 'Spectrum-CETB:main' into Sai-Spectrum-HF2022
Browse files Browse the repository at this point in the history
  • Loading branch information
sainanda59 authored Oct 3, 2022
2 parents 2a3769d + f2e3d46 commit 29c1d05
Show file tree
Hide file tree
Showing 30 changed files with 31,913 additions and 1 deletion.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ Coding enthusiasts and even beginners to open-source can contribute to these pro
[<img src="https://img.shields.io/badge/github-%2324292e.svg?&style=for-the-badge&logo=github&logoColor=white">](https://github.com/Spectrum-CETB)
[<img src="https://img.shields.io/badge/linkedin-%230077B5.svg?&style=for-the-badge&logo=linkedin&logoColor=white">](https://www.linkedin.com/company/spectrum-cet/mycompany/)
[<img src="https://img.shields.io/badge/instagram-%23E4405F.svg?&style=for-the-badge&logo=instagram&logoColor=white">](https://www.instagram.com/spectrum.cetb/)
[<img src="https://img.shields.io/badge/Discord-7289DA?style=for-the-badge&logo=discord&logoColor=white">](https://discord.gg/U2PzJavujD)

## Happy Coding💻 !

29 changes: 29 additions & 0 deletions coding_freshmen/C++/Prateek_Rath/MAJORITY_ELEMENT.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#include <bits/stdc++.h>
using namespace std;
#define ll long long


int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int n;
cin >> n;
int arr[n];
for (int i = 0; i < n;i++){
cin >> arr[i];
}
int candidate = arr[0], count = 1;
for (int i = 1; i < n;i++){
if(arr[i]==candidate){
count++;
}else{
count--;
}
if(count==0){
candidate = arr[i];
count = 1;
}
}
cout << candidate << endl;
return 0;
}
21 changes: 20 additions & 1 deletion coding_freshmen/C++/Prateek_Rath/README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,23 @@
# Problem Title: SORT_01
# 1. Problem Title: Majority Element
Find the majority element in an array.

# Problem Explanation 🚀
A majority element is an element that appears more than n/2 times in the array, where n is the size of the array.

# Logic and Intuition 🧠
* An optimized approach will be to create a frequency array and store the frequency of each element that we iterate through the array, and finally check if the frequency of any element is greater than n/2 then that element is out majority element. The time complexity of this approach is O(n) and it has an additional space complexity of O(n) as well.
* This can be further optimized by using [Moore's Voting Algorithm](https://en.wikipedia.org/wiki/Boyer%E2%80%93Moore_majority_vote_algorithm) which can solve the problem in constant space.
* In this algorithm we choose a candidate for majority element starting from the first element of the array, and we also initialize a count variable with 1.
* Then we start traversing the array and if the element encountered is same as the candidate element then we increase the count by 1 else we decrement the count by 1.
* If the count reaches 0 then we reset the candidate with the current element and reset the count to 1.
* Finally we return the candidate and if the array always has a majority element then the candidate will be the answer.

# Time Complexity and Space Complexity
* Time Complexity: O(n)
* Space Complexity: O(1)


# 2. Problem Title: SORT_01
Sort an array consisting of 0s and 1s

# Problem Explanation 🚀
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Cryptoverse

<a href="https://github.com/Spectrum-CETB/Spectober_Fest/tree/main/projects_Intermediate"><img src="https://img.shields.io/badge/Projects%20-Intermediate-blue.svg"/></a>

## Tech Stack
`Javascript` `ReactJS` `Redux` `Ant-design`

## Description
* Cryptoverse is a cryptocurrency tracker application built with react, where user can get all the information about the top cryptocurrencies, latest market changes, price charts and detailed information about each cryptocurrency's performance, market cap, rankings, growth/fall and all the latest news about the crypto market.
* It fetches the latest crypto data from the coinranking API, and uses Redux-toolkit to implement the functionality and ant-design for an elegant UI.

## Project Link
Hosted live link (vercel) : [Cryptoverse](https://cryptoverse-iampsr8.vercel.app/)

# Project Demo View
![](https://github.com/iampsr8/cryptoverse/blob/master/display/crypto1.png)

![](https://github.com/iampsr8/cryptoverse/blob/master/display/crypto2.png)




Loading

0 comments on commit 29c1d05

Please sign in to comment.