├── .github └── ISSUE_TEMPLATE │ └── bug_report.md ├── 110A - Lucky Number.md ├── Address Book.py ├── Advance_housing_Data_Analysis.ipynb ├── AutoTypeSample.py ├── AutomateFBlogin.py ├── Bitwise operations.cpp ├── Breathe First Search.java ├── CODE_OF_CONDUCT.md ├── CONTRIBUTING.md ├── Chef_and_his_bookstore.cpp ├── CountSetBits.cpp ├── Count_number _of_ways_to_reach_a_given_score_in_game.java ├── Cricket_game.cpp ├── DFS.java ├── Data Structures ├── Hashmap │ ├── hashmap.cpp │ ├── hashmapClass.h │ └── node.h ├── Stack Using Arrays │ ├── stack.cpp │ └── stackClass.cpp ├── Stack Using Linked List │ ├── nodeClass.cpp │ ├── stack.cpp │ └── stackUsingLL.cpp └── Trees │ ├── Binary Trees │ ├── binaryTreeNode.h │ └── binaryTress.cpp │ └── Generic Trees │ ├── genericTrees.cpp │ └── treenode.h ├── Fibonacci sequence.py ├── Find subarray with given sum ├── Floyd Algorithm.c ├── Implementation_of_Two_Stacks_in_one_Array.cpp ├── Infix-prefix.cpp ├── Insertion Sort in Java ├── InteractiveStudentRecords.c ├── Joesphus_Problem.c ├── KClosestPointstoOrigin.cpp ├── KFoldTargetEncoder.py ├── LICENSE ├── LinkedListQueue.cpp ├── LongestPalindromicSubstring.cpp ├── MergeSort.cpp ├── OTP_GENERATOR.py ├── PalindromeNumber.cpp ├── PalindromeString.cpp ├── Quicksort.cpp ├── README.md ├── RemoveDuplicates.cpp ├── ShellSort.cpp ├── TicTacToe.cpp ├── TwitterHashtagScrape.py ├── URLshortener.py ├── VoiceRecorderAPP.py ├── arithematic-slices.py ├── binarySearch.cpp ├── bitsinnumber.py ├── bubble-sort.cpp ├── bucketsort.cpp ├── coin_change.java ├── contribute.md ├── decimal_to_binary.sh ├── hands on loops and if-else in python.py ├── heap_sort.cpp ├── implement_trie.py ├── jump_search.cpp ├── largest_divisible_subset.py ├── longest_common_subsequence.java ├── merge sort.py ├── min_cost_path.java ├── non-overlapping-intervals.py ├── password-suggester.py ├── rand_func.c ├── rock_paper_scissor.java ├── romanNumeral.cpp ├── seive_of_eratothenes.cpp ├── selection_sort.py ├── stackmain.java ├── style.css ├── text_to_speech.py ├── transpose_of_sparse_matrix.cpp ├── twoSum.cpp ├── unique-path.cpp └── welcome.html /.github/ISSUE_TEMPLATE/bug_report.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Bug report 3 | about: Create a report to help us improve 4 | title: '' 5 | labels: '' 6 | assignees: '' 7 | 8 | --- 9 | 10 | **Describe the bug** 11 | A clear and concise description of what the bug is. 12 | 13 | **To Reproduce** 14 | Steps to reproduce the behavior: 15 | 1. Go to '...' 16 | 2. Click on '....' 17 | 3. Scroll down to '....' 18 | 4. See error 19 | 20 | **Expected behavior** 21 | A clear and concise description of what you expected to happen. 22 | 23 | **Screenshots** 24 | If applicable, add screenshots to help explain your problem. 25 | 26 | **Desktop (please complete the following information):** 27 | - OS: [e.g. iOS] 28 | - Browser [e.g. chrome, safari] 29 | - Version [e.g. 22] 30 | 31 | **Smartphone (please complete the following information):** 32 | - Device: [e.g. iPhone6] 33 | - OS: [e.g. iOS8.1] 34 | - Browser [e.g. stock browser, safari] 35 | - Version [e.g. 22] 36 | 37 | **Additional context** 38 | Add any other context about the problem here. 39 | -------------------------------------------------------------------------------- /110A - Lucky Number.md: -------------------------------------------------------------------------------- 1 | **Question Link** :- [Click Here](https://codeforces.com/problemset/problem/110/A) 2 | 3 | ```cpp 4 | #include 5 | #include 6 | using namespace std; 7 | typedef long long ll; 8 | 9 | int main(){ 10 | 11 | string s; 12 | cin >> s; 13 | ll len = s.length(),count=0; 14 | 15 | // Counting the number of 4 and 7 in the given number or string 16 | for(ll i=0; i 3 | using namespace std; 4 | 5 | int main() { 6 | // a = 5(00000101), b = 9(00001001) 7 | int a = 5, b = 9; 8 | 9 | // The result is 00000001 10 | cout<<"a = " << a <<","<< " b = " << b <> 1 "<<"= " << (b >> 1 )< adj[]; //Adjacency Lists 12 | 13 | // Constructor 14 | Graph(int v) 15 | { 16 | V = v; 17 | adj = new LinkedList[v]; 18 | for (int i=0; i queue = new LinkedList(); 37 | 38 | // Mark the current node as visited and enqueue it 39 | visited[s]=true; 40 | queue.add(s); 41 | 42 | while (queue.size() != 0) 43 | { 44 | // Dequeue a vertex from queue and print it 45 | s = queue.poll(); 46 | System.out.print(s+" "); 47 | 48 | // Get all adjacent vertices of the dequeued vertex s 49 | // If a adjacent has not been visited, then mark it 50 | // visited and enqueue it 51 | Iterator i = adj[s].listIterator(); 52 | while (i.hasNext()) 53 | { 54 | int n = i.next(); 55 | if (!visited[n]) 56 | { 57 | visited[n] = true; 58 | queue.add(n); 59 | } 60 | } 61 | } 62 | } 63 | 64 | // Driver method to 65 | public static void main(String args[]) 66 | { 67 | Graph g = new Graph(4); 68 | 69 | g.addEdge(0, 1); 70 | g.addEdge(0, 2); 71 | g.addEdge(1, 2); 72 | g.addEdge(2, 0); 73 | g.addEdge(2, 3); 74 | g.addEdge(3, 3); 75 | 76 | System.out.println("Following is Breadth First Traversal "+ 77 | "(starting from vertex 2)"); 78 | 79 | g.BFS(2); 80 | } 81 | } 82 | -------------------------------------------------------------------------------- /CODE_OF_CONDUCT.md: -------------------------------------------------------------------------------- 1 | # Contributor Covenant Code of Conduct 2 | 3 | ## Our Pledge 4 | 5 | We as members, contributors, and leaders pledge to make participation in our 6 | community a harassment-free experience for everyone, regardless of age, body 7 | size, visible or invisible disability, ethnicity, sex characteristics, gender 8 | identity and expression, level of experience, education, socio-economic status, 9 | nationality, personal appearance, race, religion, or sexual identity 10 | and orientation. 11 | 12 | We pledge to act and interact in ways that contribute to an open, welcoming, 13 | diverse, inclusive, and healthy community. 14 | 15 | ## Our Standards 16 | 17 | Examples of behavior that contributes to a positive environment for our 18 | community include: 19 | 20 | * Demonstrating empathy and kindness toward other people 21 | * Being respectful of differing opinions, viewpoints, and experiences 22 | * Giving and gracefully accepting constructive feedback 23 | * Accepting responsibility and apologizing to those affected by our mistakes, 24 | and learning from the experience 25 | * Focusing on what is best not just for us as individuals, but for the 26 | overall community 27 | 28 | Examples of unacceptable behavior include: 29 | 30 | * The use of sexualized language or imagery, and sexual attention or 31 | advances of any kind 32 | * Trolling, insulting or derogatory comments, and personal or political attacks 33 | * Public or private harassment 34 | * Publishing others' private information, such as a physical or email 35 | address, without their explicit permission 36 | * Other conduct which could reasonably be considered inappropriate in a 37 | professional setting 38 | 39 | ## Enforcement Responsibilities 40 | 41 | Community leaders are responsible for clarifying and enforcing our standards of 42 | acceptable behavior and will take appropriate and fair corrective action in 43 | response to any behavior that they deem inappropriate, threatening, offensive, 44 | or harmful. 45 | 46 | Community leaders have the right and responsibility to remove, edit, or reject 47 | comments, commits, code, wiki edits, issues, and other contributions that are 48 | not aligned to this Code of Conduct, and will communicate reasons for moderation 49 | decisions when appropriate. 50 | 51 | ## Scope 52 | 53 | This Code of Conduct applies within all community spaces, and also applies when 54 | an individual is officially representing the community in public spaces. 55 | Examples of representing our community include using an official e-mail address, 56 | posting via an official social media account, or acting as an appointed 57 | representative at an online or offline event. 58 | 59 | ## Enforcement 60 | 61 | Instances of abusive, harassing, or otherwise unacceptable behavior may be 62 | reported to the community leaders responsible for enforcement at 63 | srinidh-007@github.com. 64 | All complaints will be reviewed and investigated promptly and fairly. 65 | 66 | All community leaders are obligated to respect the privacy and security of the 67 | reporter of any incident. 68 | 69 | ## Enforcement Guidelines 70 | 71 | Community leaders will follow these Community Impact Guidelines in determining 72 | the consequences for any action they deem in violation of this Code of Conduct: 73 | 74 | ### 1. Correction 75 | 76 | **Community Impact**: Use of inappropriate language or other behavior deemed 77 | unprofessional or unwelcome in the community. 78 | 79 | **Consequence**: A private, written warning from community leaders, providing 80 | clarity around the nature of the violation and an explanation of why the 81 | behavior was inappropriate. A public apology may be requested. 82 | 83 | ### 2. Warning 84 | 85 | **Community Impact**: A violation through a single incident or series 86 | of actions. 87 | 88 | **Consequence**: A warning with consequences for continued behavior. No 89 | interaction with the people involved, including unsolicited interaction with 90 | those enforcing the Code of Conduct, for a specified period of time. This 91 | includes avoiding interactions in community spaces as well as external channels 92 | like social media. Violating these terms may lead to a temporary or 93 | permanent ban. 94 | 95 | ### 3. Temporary Ban 96 | 97 | **Community Impact**: A serious violation of community standards, including 98 | sustained inappropriate behavior. 99 | 100 | **Consequence**: A temporary ban from any sort of interaction or public 101 | communication with the community for a specified period of time. No public or 102 | private interaction with the people involved, including unsolicited interaction 103 | with those enforcing the Code of Conduct, is allowed during this period. 104 | Violating these terms may lead to a permanent ban. 105 | 106 | ### 4. Permanent Ban 107 | 108 | **Community Impact**: Demonstrating a pattern of violation of community 109 | standards, including sustained inappropriate behavior, harassment of an 110 | individual, or aggression toward or disparagement of classes of individuals. 111 | 112 | **Consequence**: A permanent ban from any sort of public interaction within 113 | the community. 114 | 115 | ## Attribution 116 | 117 | This Code of Conduct is adapted from the [Contributor Covenant][homepage], 118 | version 2.0, available at 119 | https://www.contributor-covenant.org/version/2/0/code_of_conduct.html. 120 | 121 | Community Impact Guidelines were inspired by [Mozilla's code of conduct 122 | enforcement ladder](https://github.com/mozilla/diversity). 123 | 124 | [homepage]: https://www.contributor-covenant.org 125 | 126 | For answers to common questions about this code of conduct, see the FAQ at 127 | https://www.contributor-covenant.org/faq. Translations are available at 128 | https://www.contributor-covenant.org/translations. 129 | -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | ## Contributing 2 | 3 | Hey there! We're thrilled that you'd like to contribute to this project. Your help is essential for keeping it great. 4 | 5 | Please note that this project is released with a [Contributor Code of Conduct](https://github.com/srinidh-007/HackotberFest2021/blob/main/CODE_OF_CONDUCT.md). By participating in this project you agree to abide by its terms. 6 | 7 | # Rules & Regulations 8 | 9 | - Use any language. 10 | - Don't spam it will be rejected immediately 11 | - Python, C, C++, Java, Docker, JavaScript, Node, Data Structure and Algorithms, HTML, CSS, WebDev, Android Projects are Encouraged 12 | - Anything valuable for Community 13 | - Please check for the file your contributing is already available or not if it is available contribute something new, duplicate content will be -rejected immediately 14 | 15 | ## Issues and PRs 16 | 17 | This is a beginner friendly repository where all those people who are new to open source can contribute. 18 | The unique thing is you can use any language of your choice be it Python, C, C++, Java or useful projects written in HTML, CSS, JavaScript, Node, Data Structure and Algorithms, Android Projects which would be considered valuable to the open source community as a whole. Interested? See the #how to contribute. 19 | 20 | ## How to Contribute 21 | 22 | - Take a look at the Existing [Issues](https://github.com/srinidh-007/HackotberFest2021.git) or create your own Prs with any language! 23 | - Fork the Repo so that you have a local copy then clone it into your PC. 24 | - Create a Pull Request which will be promptly reviewed and suggestions would be added to improve it. 25 | 26 | ## How to make a Pull Request 27 | 28 | **1.** Fork the repository by clicking on the symbol at the top right corner. 29 | 30 | **2.** Clone the forked repository. 31 | ``` 32 | git clone https://github.com/srinidh-007/HackotberFest2021.git 33 | ``` 34 | 35 | **3.** Make changes in source code using any code editor. 36 | 37 | **4.** Stage your changes and commit 38 | 39 | ``` 40 | git add . 41 | ``` 42 | 43 | ``` 44 | git commit -m "" 45 | ``` 46 | 47 | **5.** Push your local commits to the remote repo. 48 | 49 | ``` 50 | git push 51 | ``` 52 | 53 | **6.** Create a [PR](https://help.github.com/en/github/collaborating-with-issues-and-pull-requests/creating-a-pull-request) 54 | 55 | ## Resources 56 | 57 | - [How to Contribute to Open Source](https://opensource.guide/how-to-contribute/) 58 | - [Using Pull Requests](https://help.github.com/articles/about-pull-requests/) 59 | - [GitHub Help](https://help.github.com) 60 | -------------------------------------------------------------------------------- /Chef_and_his_bookstore.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | https://www.codechef.com/CDSP2021/problems/SEPT202 3 | 4 | Chef is giving a offer in his new opened bookstore “anyone can take three and pay for the only two more expensive ones”. So, each customer who picks three books 5 | gets the cheapest one for free. The customer can take even more books and, depending on the way the books are arranged into groups of three, get the cheapest one 6 | in each group for free. For eg,say if the prices of the books taken by the customer be: 2,3,4,5,6,7,8. If he arranges them into the groups (8,3,2), (5,6,4) and (7), 7 | he will get the book priced 2 from the first group for free and the book priced 4 from the second group. We can see that he will not get anything for free from the 8 | third group because it contains only one book. The chef working in the bookstore is good-hearted and he always wants to lower the price for each customer as much as 9 | possible. For given book prices, help the chef arrange the books into groups in the best way possible, so that the total price the customer has to pay is minimal. 10 | Please note: The chef doesn’t have to arrange the books into groups so that each group contains exactly 3 books, but the number of books in a group needs to be 11 | between 1 and 3, inclusively. 12 | 13 | Input Format 14 | The first line of input contains the integer N (1≤N≤100000), the number of books the customer bought. Each of the following N lines contains a single integer 15 | Ci (1≤Ci≤100000), the price of each book. 16 | 17 | Output Format 18 | The first and only line of output must contain the required minimal price. 19 | 20 | Sample Input 1 21 | 4 22 | 3 23 | 2 24 | 3 25 | 2 26 | 27 | Sample Output 1 28 | 8 29 | */ 30 | 31 | #include 32 | #include 33 | #include 34 | using namespace std; 35 | int main() { 36 | int n; 37 | cin >> n; 38 | vector v; 39 | for(int i = 0; i < n; i++) { 40 | int price; 41 | cin >> price; 42 | v.push_back(price); //taking input and storing in vector 43 | } 44 | 45 | sort(v.rbegin(), v.rend()); //sorting the vector 46 | int cost = 0; 47 | for(int j = 0; j < v.size(); j++) { 48 | if(j % 3 != 2) { //checking condition if satisfy operation is performed 49 | cost += v[j]; 50 | } 51 | } 52 | cout << cost << endl; //end result 53 | } 54 | -------------------------------------------------------------------------------- /CountSetBits.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | int simple_1(int n) 4 | { 5 | int res = 0; 6 | while (n > 0) 7 | { 8 | res+=(n&1); 9 | 10 | n=n>>1; 11 | } 12 | return res; 13 | } 14 | int b_and_k_algo(int n) 15 | { 16 | int res=0; 17 | while(n>0) 18 | { 19 | n=(n&(n-1)); /* when we do n-1 it turn's on all the off bits before last on bits and turn's off the last on bits so this 20 | way we can skip counting all the zeros*/ 21 | res++; 22 | } 23 | return res++; 24 | } 25 | int main() 26 | { 27 | cout << "NUMBER OF SET BITS :" << simple_1(8) << endl; 28 | cout << "NUMBER OF SET BITS :" << b_and_k_algo(8) << endl; 29 | return 0; 30 | } -------------------------------------------------------------------------------- /Count_number _of_ways_to_reach_a_given_score_in_game.java: -------------------------------------------------------------------------------- 1 | // Java program to count number of 2 | // possible ways to a given score 3 | // can be reached in a game where 4 | // a move can earn 3 or 5 or 10 5 | import java.util.Arrays; 6 | 7 | class GFG 8 | { 9 | // Returns number of ways to reach score n 10 | static int count(int n) 11 | { 12 | // table[i] will store count of solutions for 13 | // value i. 14 | int table[] = new int[n + 1], i; 15 | 16 | // Initialize all table values as 0 17 | Arrays.fill(table, 0); 18 | 19 | // Base case (If given value is 0) 20 | table[0] = 1; 21 | 22 | // One by one consider given 3 23 | // moves and update the table[] 24 | // values after the index greater 25 | // than or equal to the value of 26 | // the picked move 27 | for (i = 3; i <= n; i++) 28 | table[i] += table[i - 3]; 29 | for (i = 5; i <= n; i++) 30 | table[i] += table[i - 5]; 31 | for (i = 10; i <= n; i++) 32 | table[i] += table[i - 10]; 33 | 34 | return table[n]; 35 | } 36 | 37 | // Driver code 38 | public static void main (String[] args) 39 | { 40 | int n = 20; 41 | System.out.println("Count for "+n+" is "+count(n)); 42 | 43 | n = 13; 44 | System.out.println("Count for "+n+" is "+count(n)); 45 | } 46 | } 47 | 48 | 49 | -------------------------------------------------------------------------------- /Cricket_game.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | using namespace std; 5 | 6 | // Driver Code 7 | int main() 8 | { 9 | int totalrun = 0; 10 | srand(time(0)); 11 | int i; 12 | 13 | // Generate a random number 14 | // and store in variable 15 | i = (rand() % 25) + 1; 16 | cout << "~~~~~~~~ CRICKET GAME ~~~" 17 | << "~~~~~~~" << endl; 18 | 19 | // Displaying the winning score 20 | cout << "Your winning score " 21 | << i << "\n"; 22 | 23 | // while loop for true condition 24 | while (1) 25 | { 26 | int player = 0; 27 | int a; 28 | 29 | if (totalrun > i) 30 | { 31 | cout << "you won your score=" 32 | << totalrun << "\n"; 33 | 34 | // To exit loop 35 | exit(0); 36 | } 37 | else 38 | { 39 | 40 | // Generate random no. and 41 | // store in a variable 42 | a = (rand() % 6) + 1; 43 | cout << "Enter no. between " 44 | << "1 to 6" << endl; 45 | 46 | // Taking input from user 47 | // to score runs 48 | cin >> player; 49 | 50 | // Checking if user's score 51 | // exceeds the winning score 52 | // Displaying random number 53 | // taken by system on screen 54 | cout << "System: " << a << endl; 55 | 56 | // Check if number inserted 57 | // by user is the same random 58 | // number generated by system 59 | // inside loop 60 | if (player == a) 61 | { 62 | cout << "OUT your score =" 63 | << totalrun 64 | << endl; 65 | 66 | // To exit loop 67 | exit(0); 68 | } 69 | 70 | // Storing total runs scored 71 | // by user 72 | else 73 | { 74 | totalrun = totalrun + player; 75 | } 76 | } 77 | } 78 | 79 | return 0; 80 | } -------------------------------------------------------------------------------- /DFS.java: -------------------------------------------------------------------------------- 1 | // Java program to print DFS 2 | 3 | import java.io.*; 4 | import java.util.*; 5 | 6 | // This class represents a 7 | // directed graph using adjacency 8 | // list representation 9 | class Graph { 10 | private int V; // No. of vertices 11 | 12 | // Array of lists for 13 | // Adjacency List Representation 14 | private LinkedList adj[]; 15 | 16 | // Constructor 17 | @SuppressWarnings("unchecked") Graph(int v) 18 | { 19 | V = v; 20 | adj = new LinkedList[v]; 21 | for (int i = 0; i < v; ++i) 22 | adj[i] = new LinkedList(); 23 | } 24 | 25 | // Function to add an edge into the graph 26 | void addEdge(int v, int w) 27 | { 28 | adj[v].add(w); // Add w to v's list. 29 | } 30 | 31 | // A function used by DFS 32 | void DFSUtil(int v, boolean visited[]) 33 | { 34 | // Mark the current node as visited and print it 35 | visited[v] = true; 36 | System.out.print(v + " "); 37 | 38 | // Recur for all the vertices adjacent to this 39 | // vertex 40 | Iterator i = adj[v].listIterator(); 41 | while (i.hasNext()) 42 | { 43 | int n = i.next(); 44 | if (!visited[n]) 45 | DFSUtil(n, visited); 46 | } 47 | } 48 | 49 | // The function to do DFS traversal. 50 | // It uses recursive 51 | // DFSUtil() 52 | void DFS(int v) 53 | { 54 | // Mark all the vertices as 55 | // not visited(set as 56 | // false by default in java) 57 | boolean visited[] = new boolean[V]; 58 | 59 | // Call the recursive helper 60 | // function to print DFS 61 | // traversal 62 | DFSUtil(v, visited); 63 | } 64 | 65 | // Driver Code 66 | public static void main(String args[]) 67 | { 68 | Graph g = new Graph(4); 69 | 70 | g.addEdge(0, 3); 71 | g.addEdge(0, 2); 72 | g.addEdge(1, 2); 73 | g.addEdge(2, 0); 74 | g.addEdge(2, 3); 75 | g.addEdge(3, 3); 76 | 77 | System.out.println( 78 | "Following is Depth First Traversal " 79 | + "(starting from vertex 2)"); 80 | 81 | g.DFS(2); 82 | } 83 | } 84 | -------------------------------------------------------------------------------- /Data Structures/Hashmap/hashmap.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include "hashmapClass.h" 3 | #include 4 | using namespace std; 5 | 6 | 7 | int main (){ 8 | map ourmap(13); 9 | string key; 10 | int value; 11 | cout << "Enter key (Enter 0 for termination) : "; 12 | cin >> key; 13 | while (key != "0"){ 14 | cout << "Enter Value of " << key << " : "; 15 | cin >> value; 16 | ourmap.insert(key,value); 17 | cout << "Enter another key (Enter 0 for termination) : "; 18 | cin >> key; 19 | } 20 | cout << endl; 21 | ourmap.display(); 22 | 23 | ourmap.removeKey("Gopal"); 24 | cout << "List after removing key" << endl; 25 | ourmap.display(); 26 | return 0; 27 | } -------------------------------------------------------------------------------- /Data Structures/Hashmap/hashmapClass.h: -------------------------------------------------------------------------------- 1 | #include 2 | #include "node.h" 3 | #include 4 | using namespace std; 5 | 6 | template 7 | class map { 8 | public: 9 | node ** array; 10 | int count; 11 | int bucketSize; 12 | 13 | map(int bucketSize){ 14 | this -> bucketSize = bucketSize; 15 | count = 0; 16 | array = new node*[bucketSize]; 17 | for (int i =0;i * temp = array[bucketIndex]; 36 | while (temp != NULL){ 37 | if (temp -> key == key){ 38 | temp -> value = value; 39 | return; 40 | } 41 | temp = temp -> next; 42 | } 43 | temp = array[bucketIndex]; 44 | node * newNode = new node(key,value); 45 | newNode -> next = temp; 46 | array[bucketIndex] = newNode; 47 | count++; 48 | } 49 | 50 | t getValue(string key){ 51 | int bucketIndex = getBucketIndex(key); 52 | node * head = array[bucketIndex]; 53 | while (head != NULL){ 54 | if (head -> key == key){ 55 | return head -> value; 56 | } 57 | head = head -> next; 58 | } 59 | return 0; 60 | } 61 | 62 | t removeKey(string key){ 63 | int bucketIndex = getBucketIndex(key); 64 | cout << "bucketIndex for " << key << " is " << bucketIndex << endl; 65 | node * head = array[bucketIndex]; 66 | cout << "Key " << head -> key << endl; 67 | node * prev = NULL; 68 | while (head != NULL){ 69 | cout << "This is working"; 70 | if (head -> key == key){ 71 | if (prev == NULL){ 72 | array[bucketIndex] = head -> next; 73 | 74 | }else{ 75 | prev -> next = head -> next; 76 | } 77 | cout << "This is working too"; 78 | head -> next = NULL; 79 | t value = head -> value; 80 | delete head; 81 | count--; 82 | return value; 83 | } 84 | prev = head; 85 | head = head -> next; 86 | } 87 | return 0; 88 | } 89 | 90 | 91 | void display(){ 92 | for (int i =0;i * head){ 111 | while(head != NULL){ 112 | cout << "(" << head -> key << " , " << head -> value << ")" << endl; 113 | head = head -> next; 114 | } 115 | } 116 | }; -------------------------------------------------------------------------------- /Data Structures/Hashmap/node.h: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | using namespace std; 4 | 5 | template 6 | class node { 7 | public: 8 | string key; 9 | t value; 10 | node * next; 11 | 12 | node(string key, t value){ 13 | this -> key = key; 14 | this -> value = value; 15 | next = NULL; 16 | } 17 | 18 | ~node(){ 19 | delete next; 20 | } 21 | }; -------------------------------------------------------------------------------- /Data Structures/Stack Using Arrays/stack.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include "stackClass.cpp" 3 | using namespace std; 4 | 5 | // dynamic stack, changes it size acc to input 6 | 7 | int main (){ 8 | stack s1(5); 9 | for (int i=0;i<5;i++){ 10 | s1.push(i+1); 11 | } 12 | s1.display(); 13 | stack s2(5); 14 | s2.push('h'); 15 | s2.display(); 16 | 17 | s1.push(6); 18 | s1.push(7); 19 | s1.display(); 20 | cout << s1.getSize(); 21 | cout << endl; 22 | stack s3; 23 | cout << s3.getSize(); 24 | return 0; 25 | } -------------------------------------------------------------------------------- /Data Structures/Stack Using Arrays/stackClass.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | using namespace std; 4 | 5 | template 6 | class stack { 7 | t * p; 8 | int top; 9 | int size; 10 | public : 11 | 12 | stack(int size = 10){ 13 | top = -1; 14 | this -> size = size; 15 | p = new t[size]; 16 | } 17 | 18 | int getSize(){ 19 | return size; 20 | } 21 | 22 | int getTop(){ 23 | return top; 24 | } 25 | 26 | bool isEmpty(){ 27 | if (top == -1){ 28 | return true; 29 | }else { 30 | return false; 31 | } 32 | } 33 | 34 | bool isFull(){ 35 | if (top == size - 1){ 36 | return true; 37 | }else { 38 | return false; 39 | } 40 | } 41 | 42 | void push(int data){ 43 | if (isFull()){ 44 | t * a = new t[size*2]; 45 | int i; 46 | for (i=0;i 2 | using namespace std; 3 | 4 | template 5 | class node { 6 | public: 7 | 8 | v data; 9 | node * next; 10 | 11 | node(v data){ 12 | this -> data = data; 13 | next = NULL; 14 | } 15 | }; 16 | -------------------------------------------------------------------------------- /Data Structures/Stack Using Linked List/stack.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include "stackUsingLL.cpp" 3 | using namespace std; 4 | 5 | 6 | int main (){ 7 | stack s1; 8 | s1.push(1); 9 | s1.push(2); 10 | s1.push(3); 11 | cout << s1.getSize() << endl; 12 | s1.display(); 13 | s1.pop(); 14 | cout << s1.getSize() << endl; 15 | s1.display(); 16 | 17 | stack s2; 18 | s2.push('h'); 19 | s2.display(); 20 | return 0; 21 | } -------------------------------------------------------------------------------- /Data Structures/Stack Using Linked List/stackUsingLL.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include "nodeClass.cpp" 3 | using namespace std; 4 | 5 | 6 | 7 | template 8 | class stack{ 9 | node * head; 10 | node * tail; 11 | 12 | int length; 13 | 14 | public: 15 | stack(){ 16 | head = NULL; 17 | tail = NULL; 18 | length = 0; 19 | } 20 | 21 | void push(t data){ 22 | node * newNode = new node(data); 23 | if (head == NULL){ 24 | head = newNode; 25 | tail = newNode; 26 | }else { 27 | tail -> next = newNode; 28 | tail = newNode; 29 | } 30 | length++; 31 | } 32 | 33 | t pop(){ 34 | node * temp = head; 35 | while (temp -> next != tail){ 36 | temp = temp -> next; 37 | } 38 | t data = tail -> data; 39 | temp -> next = NULL; 40 | tail = temp; 41 | length--; 42 | return data; 43 | } 44 | 45 | void display(){ 46 | node * temp = head; 47 | while (temp != NULL){ 48 | cout << temp -> data << " "; 49 | temp = temp -> next; 50 | } 51 | cout << endl; 52 | } 53 | 54 | int getSize(){ 55 | return length; 56 | } 57 | 58 | }; -------------------------------------------------------------------------------- /Data Structures/Trees/Binary Trees/binaryTreeNode.h: -------------------------------------------------------------------------------- 1 | template 2 | class binarynode { 3 | public: 4 | t data; 5 | binarynode * left; 6 | binarynode * right; 7 | 8 | binarynode(t data){ 9 | this -> data = data; 10 | left = right = NULL; 11 | } 12 | ~binarynode(){ 13 | delete left; 14 | delete right; 15 | } 16 | 17 | }; -------------------------------------------------------------------------------- /Data Structures/Trees/Binary Trees/binaryTress.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | #include 4 | #include 5 | #include "binaryTreeNode.h" 6 | 7 | binarynode * takeInput(){ // level wise input 8 | cout << "Enter the root data : "; 9 | int rootData; 10 | cin >> rootData; 11 | binarynode * root = new binarynode(rootData); 12 | queue *> q1; 13 | q1.push(root); 14 | while(q1.size() != 0){ 15 | binarynode * front = q1.front(); 16 | q1.pop(); 17 | cout << "Enter the left child of " << front -> data << " : "; 18 | cin >> rootData; 19 | binarynode * leftChild = (rootData != -1) ? new binarynode(rootData) : NULL; 20 | cout << "Enter the right child of " << front -> data << " : "; 21 | cin >> rootData; 22 | binarynode * rightChild = (rootData != -1) ? new binarynode(rootData) : NULL; 23 | front -> left = leftChild; 24 | front -> right = rightChild; 25 | if (leftChild != NULL) q1.push(leftChild); 26 | if (rightChild !=NULL) q1.push(rightChild); 27 | } 28 | return root; 29 | } 30 | 31 | void printTree(binarynode * root){ 32 | if (root == NULL) return; 33 | cout << root -> data << " : "; 34 | if (root -> left != NULL){ 35 | cout << "L " << root -> left -> data << " , "; 36 | } 37 | if (root -> right != NULL){ 38 | cout << "R " < right -> data << " "; 39 | } 40 | cout << endl; 41 | printTree(root -> left); 42 | printTree(root -> right); 43 | } 44 | 45 | int height(binarynode * root){ // cn way, better way infact the best way 46 | if (root == NULL) return 0; 47 | return 1 + max(height(root -> left), height(root -> right)); 48 | } 49 | 50 | int countNoOfNodes(binarynode * root){ // well done 51 | if (root == NULL) return 0; 52 | int count = 1; // on account of root node 53 | count += countNoOfNodes(root -> left) + countNoOfNodes(root -> right); 54 | return count; 55 | } 56 | 57 | int main (){ 58 | binarynode * root = takeInput(); 59 | printTree(root); 60 | cout << "Height of the tree is : " << height(root); 61 | return 0; 62 | } -------------------------------------------------------------------------------- /Data Structures/Trees/Generic Trees/genericTrees.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include "treenode.h" 3 | #include 4 | using namespace std; 5 | 6 | treenode * takeInput(){ // level wise input 7 | int rootData; 8 | cout << "Enter The Data of the Root Element : "; 9 | cin >> rootData; 10 | treenode * root = new treenode (rootData); 11 | queue *> q1; 12 | q1.push(root); 13 | while(q1.size() != 0){ 14 | treenode* front = q1.front(); 15 | q1.pop(); 16 | int noOfChildren; 17 | cout << "Enter the no of children of "<< front -> data << " : "; 18 | cin >> noOfChildren; 19 | for (int i =0;idata << " : "; 22 | cin >> nodeData; 23 | treenode * newNode = new treenode(nodeData); 24 | front -> children.push_back(newNode); 25 | q1.push(newNode); 26 | } 27 | } 28 | return root; 29 | } 30 | 31 | void printTree(treenode * root){ 32 | if (root == NULL){ 33 | return; 34 | } 35 | cout << root -> data << " : "; 36 | for (int i =0;i children.size();i++){ 37 | cout << root -> children[i]->data << " , "; 38 | } 39 | cout << endl; 40 | for (int i =0;i children.size() ; i++){ 41 | printTree(root -> children[i]); 42 | } 43 | } 44 | 45 | int noOFNodes(treenode * root){ 46 | int sum = 1; // on account of the root node 47 | for (int i =0;i children.size();i++){ 48 | sum += noOFNodes(root -> children[i]); 49 | } 50 | return sum; 51 | } 52 | 53 | int main(){ 54 | treenode * root = takeInput(); 55 | printTree(root); 56 | cout << "The no of nodes are : " << noOFNodes(root); 57 | return 0; 58 | } -------------------------------------------------------------------------------- /Data Structures/Trees/Generic Trees/treenode.h: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | template 5 | class treenode{ 6 | public: 7 | t data; 8 | vector *> children; 9 | 10 | treenode(t data){ 11 | this -> data = data; 12 | } 13 | 14 | ~treenode(){ 15 | for (int i =0;i 3 | using namespace std; 4 | 5 | /* Returns true if the there is a subarray 6 | of arr[] with sum equal to 'sum' otherwise 7 | returns false. Also, prints the result */ 8 | int subArraySum(int arr[], int n, int sum) 9 | { 10 | int curr_sum, i, j; 11 | 12 | // Pick a starting point 13 | for (i = 0; i < n; i++) { 14 | curr_sum = arr[i]; 15 | 16 | // try all subarrays starting with 'i' 17 | for (j = i + 1; j <= n; j++) { 18 | if (curr_sum == sum) { 19 | cout << "Sum found between indexes " 20 | << i << " and " << j - 1; 21 | return 1; 22 | } 23 | if (curr_sum > sum || j == n) 24 | break; 25 | curr_sum = curr_sum + arr[j]; 26 | } 27 | } 28 | 29 | cout << "No subarray found"; 30 | return 0; 31 | } 32 | 33 | // Driver Code 34 | int main() 35 | { 36 | int arr[] = { 15, 2, 4, 8, 9, 5, 10, 23 }; 37 | int n = sizeof(arr) / sizeof(arr[0]); 38 | int sum = 23; 39 | subArraySum(arr, n, sum); 40 | return 0; 41 | } 42 | 43 | -------------------------------------------------------------------------------- /Floyd Algorithm.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | typedef struct node { 5 | int data; 6 | struct node *next; 7 | int visited; 8 | } SLL; 9 | 10 | SLL *insert(SLL *head, int val) 11 | { 12 | if(head == NULL) 13 | { 14 | head = (SLL*) malloc(sizeof(SLL*)); 15 | head->data = val; 16 | head->next = NULL; 17 | head->visited = 0; 18 | } 19 | else { 20 | SLL *temp = head; 21 | while(temp->next != NULL) 22 | { 23 | temp = temp->next; 24 | } 25 | SLL *new = (SLL*) malloc(sizeof(SLL*)); 26 | new->data = val; 27 | new->next = NULL; 28 | new->visited = 0; 29 | temp->next = new; 30 | } 31 | return head; 32 | } 33 | 34 | void printList(SLL *head) 35 | { 36 | SLL*temp = head; 37 | while(temp != NULL) 38 | { 39 | printf("%d -> ",temp->data); 40 | temp = temp->next; 41 | } 42 | printf("NULL\n"); 43 | } 44 | 45 | int checkForCycles(SLL *head) 46 | { 47 | SLL *slow = head; 48 | SLL *fast = head; 49 | 50 | while(slow != NULL && fast != NULL && fast->next != NULL) 51 | { 52 | slow = slow->next; 53 | fast = fast->next->next; 54 | 55 | if(slow == fast) 56 | { 57 | return 1; 58 | } 59 | } 60 | return 0; 61 | } 62 | 63 | int main() 64 | { 65 | SLL *head = NULL; 66 | head = insert(head, 10); 67 | head = insert(head, 15); 68 | head = insert(head, 20); 69 | head = insert(head, 25); 70 | head = insert(head, 30); 71 | head = insert(head, 35); 72 | head = insert(head, 40); 73 | 74 | printList(head); 75 | 76 | // head->next->next->next->next = head; 77 | 78 | // Floyd algorithm 79 | if(checkForCycles(head)) 80 | { 81 | printf("Cycle is present in the list\n"); 82 | } 83 | else { 84 | printf("Cycle is not present in the list\n"); 85 | } 86 | 87 | return 0; 88 | } 89 | -------------------------------------------------------------------------------- /Implementation_of_Two_Stacks_in_one_Array.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | class Two_Stacks 5 | { 6 | int *arr; 7 | int t, m, n;; 8 | 9 | public: 10 | Two_Stacks(int num) 11 | { 12 | t=num; 13 | arr=new int[num]; 14 | m=-1; 15 | n=t; 16 | } 17 | 18 | 19 | void push1(int x) 20 | { 21 | 22 | if(m<(n - 1)) 23 | { 24 | m++; 25 | arr[m]=x; 26 | } 27 | else 28 | { 29 | cout<<"Stack Overflow"<=0) 51 | { 52 | int temp=arr[m]; 53 | m--; 54 | return temp; 55 | } 56 | else 57 | { 58 | cout<<"Stack UnderFlow"< 3 | using namespace std; 4 | bool isOperator(char c) 5 | { 6 | return (!isalpha(c) && !isdigit(c)); 7 | } 8 | int preceed(char a) 9 | { 10 | if(a == '+' || a == '-') 11 | return 1; 12 | else if(a == '*' || a == '/') 13 | return 2; 14 | else if(a == '^') 15 | return 3; 16 | else 17 | return -1; 18 | } 19 | string infixToPostfix(string infix) 20 | { 21 | infix = '(' + infix + ')'; 22 | stack char_stack; 23 | string output; 24 | for (int i = 0; i < infix.size(); i++) { 25 | 26 | if (isalpha(infix[i]) || isdigit(infix[i])) 27 | output += infix[i]; 28 | 29 | else if (infix[i] == '(') 30 | char_stack.push('('); 31 | 32 | else if (infix[i] == ')') { 33 | 34 | while (char_stack.top() != '(') { 35 | output += char_stack.top(); 36 | char_stack.pop(); 37 | } 38 | 39 | char_stack.pop(); 40 | } 41 | 42 | else { 43 | 44 | if (isOperator(char_stack.top())) { 45 | while (preceed(infix[i]) <= preceed(char_stack.top())) { 46 | output += char_stack.top(); 47 | char_stack.pop(); 48 | } 49 | char_stack.push(infix[i]); 50 | } 51 | } 52 | } 53 | return output; 54 | } 55 | 56 | string infixToPrefix(string infix) 57 | { 58 | 59 | reverse(infix.begin(), infix.end()); 60 | for (int i = 0; i < infix.size(); i++) { 61 | 62 | if (infix[i] == '(') { 63 | infix[i] = ')'; 64 | i++; 65 | } 66 | else if (infix[i] == ')') { 67 | infix[i] = '('; 68 | i++; 69 | } 70 | } 71 | 72 | string prefix = infixToPostfix(infix); 73 | reverse(prefix.begin(), prefix.end()); 74 | return prefix; 75 | } 76 | 77 | 78 | int main() 79 | { 80 | string s = ("(a+(b/c)*(d^e)-f)"); 81 | cout << infixToPrefix(s) << std::endl; 82 | return 0; 83 | } -------------------------------------------------------------------------------- /Insertion Sort in Java: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /InteractiveStudentRecords.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | //disclaimer : There are 5 courses and they are labeled 101,102,103,104 and 105 respectively. 5 | int count = 0; 6 | struct data 7 | { 8 | char firstName[15]; 9 | char lastName[15]; 10 | int rollno; 11 | float cgpa; 12 | int course[2]; 13 | }in[49]; 14 | void addStdudent() 15 | { 16 | printf("First Name : "); 17 | scanf("%s",in[count].firstName); 18 | printf("\nLast Name : "); 19 | scanf("%s",in[count].lastName); 20 | printf("\nRoll no. : "); 21 | scanf("%d",&in[count].rollno); 22 | printf("\nCGPA : "); 23 | scanf("%f",&in[count].cgpa); 24 | printf("\nCourses enrolled in : "); 25 | for(int i=0;i<2;i++) 26 | scanf("%d",&in[count].course[i]); 27 | count ++; 28 | } 29 | void findStudent() 30 | { 31 | int yes=0; 32 | int roll; 33 | printf("Roll No. : "); 34 | scanf("&d",&roll); 35 | for(int i=0;ivalue[j]) 167 | { 168 | temp=value[i]; 169 | value[i]=value[j]; 170 | value[j]=temp; 171 | } 172 | } 173 | } 174 | if(count%2==0) 175 | printf("Median of CGPAs is : %.2f\n",value[count/2]); 176 | else if(count%2!=0) 177 | printf("Median of CGPAs is : %.2f\n",value[(count+1)/2]); 178 | float num=0; 179 | for(int i=0;i 2 | int josephus(int n, int k) 3 | { 4 | //This is Index 5 | if(n==1) 6 | return 0; 7 | 8 | int x=josephus(n-1,k); 9 | int y=(x+k)%n; 10 | return y; 11 | } 12 | 13 | // Driver Program to test above function 14 | int main() 15 | { 16 | int T; 17 | //Testcases 18 | printf("No of Test Cases: "); 19 | scanf("%d",&T); 20 | int count=1; 21 | while (T--) 22 | { 23 | printf("\nTest case : %d", count); 24 | int N; 25 | //taking input N 26 | printf("\nEnter no of Persons: "); 27 | scanf("%d",&N); 28 | int K; 29 | //taking input K 30 | printf("NOTE: K indicates that K-1 persons are skipped and Kth person is killed in circle. "); 31 | printf("\nEnter K value: "); 32 | scanf("%d",&K); 33 | printf("The chosen place is %d\n", 1+josephus(N, K)); 34 | count++; 35 | } 36 | return 0; 37 | } -------------------------------------------------------------------------------- /KClosestPointstoOrigin.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | // Comparator class to assign 5 | // priority to coordinates 6 | class comp { 7 | 8 | public: 9 | bool operator()(pair a, 10 | pair b) 11 | { 12 | int x1 = a.first * a.first; 13 | int y1 = a.second * a.second; 14 | int x2 = b.first * b.first; 15 | int y2 = b.second * b.second; 16 | 17 | // return true if distance 18 | // of point 1 from origin 19 | // is greater than distance of 20 | // point 2 from origin 21 | return (x1 + y1) > (x2 + y2); 22 | } 23 | }; 24 | 25 | void kClosestPoints(int x[], int y[], 26 | int n, int k) 27 | { 28 | // Priority queue 29 | priority_queue, 30 | vector >, 31 | comp> 32 | pq; 33 | 34 | for (int i = 0; i < n; i++) { 35 | pq.push(make_pair(x[i], y[i])); 36 | } 37 | 38 | for (int i = 0; i < k; i++) { 39 | 40 | pair p = pq.top(); 41 | 42 | cout << p.first << " " 43 | << p.second << endl; 44 | 45 | pq.pop(); 46 | } 47 | } 48 | int main() 49 | { 50 | 51 | int x[] = { 1, -2 }; 52 | 53 | 54 | int y[] = { 3, 2 }; 55 | int K = 1; 56 | 57 | int n = sizeof(x) / sizeof(x[0]); 58 | 59 | kClosestPoints(x, y, n, K); 60 | 61 | return 0; 62 | } -------------------------------------------------------------------------------- /KFoldTargetEncoder.py: -------------------------------------------------------------------------------- 1 | import numpy as np 2 | import pandas as pd 3 | from sklearn import base 4 | from sklearn.model_selection import KFold 5 | 6 | 7 | class KFoldTargetEncoderTrain(base.BaseEstimator, base.TransformerMixin): 8 | def __init__(self,colnames,targetName, n_fold=5, verbosity=True, discardOriginal_col=False): 9 | self.colnames = colnames 10 | self.targetName = targetName 11 | self.n_fold = n_fold 12 | self.verbosity = verbosity 13 | self.discardOriginal_col = discardOriginal_col 14 | 15 | def fit(self, X, y=None): 16 | return self 17 | 18 | def transform(self,X): 19 | assert(type(self.targetName) == str) 20 | assert(type(self.colnames) == str) 21 | assert(self.colnames in X.columns) 22 | assert(self.targetName in X.columns) 23 | mean_of_target = X[self.targetName].mean() 24 | kf = KFold(n_splits = self.n_fold, shuffle = True, random_state=42) 25 | col_mean_name = self.colnames + '_' + 'Kfold_Target_Enc' 26 | X[col_mean_name] = np.nan 27 | for tr_ind, val_ind in kf.split(X): 28 | X_tr, X_val = X.iloc[tr_ind], X.iloc[val_ind] 29 | X.loc[X.index[val_ind], col_mean_name] = X_val[self.colnames].map(X_tr.groupby(self.colnames)[self.targetName].mean()) 30 | X[col_mean_name].fillna(mean_of_target, inplace = True) 31 | if self.verbosity: 32 | encoded_feature = X[col_mean_name].values 33 | print('Correlation between the new feature, {} and, {} is {}.'.format(col_mean_name,self.targetName, np.corrcoef(X[self.targetName].values, encoded_feature)[0][1])) 34 | if self.discardOriginal_col: 35 | X = X.drop(self.targetName, axis=1) 36 | return X 37 | 38 | class KFoldTargetEncoderTest(base.BaseEstimator, base.TransformerMixin): 39 | 40 | def __init__(self,train,colNames,encodedName): 41 | 42 | self.train = train 43 | self.colNames = colNames 44 | self.encodedName = encodedName 45 | 46 | def fit(self, X, y=None): 47 | return self 48 | 49 | def transform(self,X): 50 | mean = self.train[[self.colNames, self.encodedName]].groupby(self.colNames).mean().reset_index() 51 | 52 | dd = {} 53 | for index, row in mean.iterrows(): 54 | dd[row[self.colNames]] = row[self.encodedName] 55 | X[self.encodedName] = X[self.colNames] 56 | X = X.replace({self.encodedName: dd}) 57 | return X 58 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2021 Srinidh Reddy 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /LinkedListQueue.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | struct node { 5 | int val; 6 | node* link; 7 | node(int num) 8 | { 9 | val = num; 10 | link = NULL; 11 | } 12 | }; 13 | 14 | struct Queue{ 15 | node *front, *rear; 16 | Queue() 17 | { 18 | front=NULL; 19 | rear=NULL; 20 | } 21 | 22 | void enqueue(int x) 23 | { 24 | node* temp = new node(x); 25 | if (rear == NULL) { 26 | front = temp; 27 | rear = temp; // adding first element 28 | return; 29 | } 30 | rear->link = temp; //linking to next node and assigning the valye temp 31 | rear = temp; 32 | 33 | } 34 | void dequeue() 35 | { 36 | if (front == NULL){ 37 | rear = NULL; 38 | return; //no elements to delete 39 | } 40 | node* temp = front; 41 | front = front->link; //removing element 1 by linking the head to the next node 42 | } 43 | void Display() { 44 | node* temp; 45 | temp = front; 46 | if ((front == NULL) && (rear == NULL)) { // if front and rear ==null then no elements in queue 47 | cout<<"Empty Queue\n"; 48 | return; 49 | } 50 | cout<<"Elements in the current Queue are : "; 51 | while (temp != NULL) { 52 | cout<val<<" "; //printing from front to rear 53 | temp = temp->link; 54 | } 55 | } 56 | }; 57 | 58 | 59 | int main() 60 | { 61 | Queue q; 62 | q.enqueue(10); 63 | q.enqueue(20); 64 | q.enqueue(30); 65 | q.dequeue(); 66 | q.enqueue(40); 67 | q.Display(); 68 | cout<<"\n"; 69 | q.enqueue(50); 70 | q.enqueue(60); 71 | q.enqueue(70); 72 | q.dequeue(); 73 | q.enqueue(80); 74 | q.dequeue(); 75 | q.Display(); 76 | cout<<"\n"; 77 | } 78 | -------------------------------------------------------------------------------- /LongestPalindromicSubstring.cpp: -------------------------------------------------------------------------------- 1 | // A C++ answer for longest palindromic substring 2 | #include 3 | using namespace std; 4 | // Function to print a substring str[low...high] 5 | void printSubStr(string str, int low, int high) 6 | { 7 | for (int i = low; i <= high; ++i) 8 | cout << str[i];; 9 | } 10 | // This function prints the largest palindrome substring 11 | // It also returns the length of the longest palindrome 12 | int longestPalindromicSubstring(string str) 13 | { 14 | // get length of input string 15 | int n = str.size(); 16 | // All substrings of length 1 are palindromes 17 | int maxLength = 1, start = 0; 18 | // Nested loop to sign start and end indexes 19 | for (int i = 0; i < str.length(); i++) { 20 | for (int j = i; j < str.length(); j++) { 21 | int flag = 1; 22 | // Check palindrome 23 | for (int k = 0; k < (j - i + 1) / 2; k++) 24 | if (str[i + k] != str[j - k]) 25 | flag = 0; 26 | // Palindrome 27 | if (flag && (j - i + 1) > maxLength) { 28 | start = i; 29 | maxLength = j - i + 1; 30 | } 31 | } 32 | } 33 | cout << "Longest palindrome substring is: " << endl; 34 | printSubStr(str, start, start + maxLength - 1); 35 | // return length of Longest palindromic substring 36 | return maxLength; 37 | } 38 | // Driver Code 39 | int main() 40 | { 41 | string str = "chennai"; 42 | cout << longestPalindromicSubstring(str) << endl; 43 | return 0; 44 | } -------------------------------------------------------------------------------- /MergeSort.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | void merge(int arr[],int mid,int left,int right){ 5 | int n1 = mid - left + 1; 6 | int n2 = right - mid; 7 | int leftArr[n1],rightArr[n2]; 8 | 9 | for(int i=0;i=right) 35 | return; 36 | 37 | int mid = left + (right-left)/2; 38 | 39 | mergeSort(arr,left,mid); 40 | mergeSort(arr,mid+1,right); 41 | merge(arr,mid,left,right); 42 | } 43 | 44 | int main(){ 45 | int n; 46 | cin>>n; 47 | int arr[n]; 48 | for(int i=0;i>arr[i]; 50 | } 51 | mergeSort(arr,0,n-1); 52 | for(int i=0;i 2 | using namespace std; 3 | 4 | int main() 5 | { 6 | int n, num, digit, reverse = 0; 7 | 8 | cout << "Enter a positive number: "; 9 | cin >> num; 10 | 11 | n = num; 12 | 13 | do 14 | { 15 | digit = num % 10; 16 | reverse = (reverse * 10) + digit; 17 | num = num / 10; 18 | } while (num != 0); 19 | 20 | cout << " The reverse of the number is: " << reverse << endl; 21 | 22 | if (n == reverse) 23 | cout << " The number is a palindrome."; 24 | else 25 | cout << " The number is not a palindrome."; 26 | 27 | return 0; 28 | } -------------------------------------------------------------------------------- /PalindromeString.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | string isPalindrome(string S) 5 | { 6 | // Stores the reverse of the 7 | // string S 8 | string P = S; 9 | 10 | // Reverse the string P 11 | reverse(P.begin(), P.end()); 12 | 13 | // If S is equal to P 14 | if (S == P) { 15 | // Return "Yes" 16 | return "Yes"; 17 | } 18 | // Otherwise 19 | else { 20 | // return "No" 21 | return "No"; 22 | } 23 | } 24 | 25 | // Driver Code 26 | int main() 27 | { 28 | string S ; 29 | cin >> S; 30 | cout << isPalindrome(S); 31 | 32 | return 0; 33 | } -------------------------------------------------------------------------------- /Quicksort.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | // Swap two elements - Utility function 4 | void swap(int *a, int *b) 5 | { 6 | int t = *a; 7 | *a = *b; 8 | *b = t; 9 | } 10 | 11 | // partition the array using last element as pivot 12 | int partition(int arr[], int low, int high) 13 | { 14 | int pivot = arr[high]; // pivot 15 | int i = (low - 1); 16 | 17 | for (int j = low; j <= high - 1; j++) 18 | { 19 | //if current element is smaller than pivot, increment the low element 20 | //swap elements at i and j 21 | if (arr[j] <= pivot) 22 | { 23 | i++; // increment index of smaller element 24 | swap(&arr[i], &arr[j]); 25 | } 26 | } 27 | swap(&arr[i + 1], &arr[high]); 28 | return (i + 1); 29 | } 30 | 31 | //quicksort algorithm 32 | void quickSort(int arr[], int low, int high) 33 | { 34 | if (low < high) 35 | { 36 | //partition the array 37 | int pivot = partition(arr, low, high); 38 | 39 | //sort the sub arrays independently 40 | quickSort(arr, low, pivot - 1); 41 | quickSort(arr, pivot + 1, high); 42 | } 43 | } 44 | 45 | void displayArray(int arr[], int size) 46 | { 47 | int i; 48 | for (i = 0; i < size; i++) 49 | cout << arr[i] << "\t"; 50 | } 51 | 52 | int main() 53 | { 54 | int arr[] = {12, 23, 3, 43, 51, 35, 19, 45}; 55 | int n = sizeof(arr) / sizeof(arr[0]); 56 | cout << "Input array" << endl; 57 | displayArray(arr, n); 58 | cout << endl; 59 | quickSort(arr, 0, n - 1); 60 | cout << "Array sorted with quick sort" << endl; 61 | displayArray(arr, n); 62 | return 0; 63 | } -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | 2 | 3 |

Hacktoberfest 2021

4 | For Beginners, students and developers this is great opportunity to learn and contribute to open source. 5 | 6 | *** 7 |

8 | 9 | Link To HacktoberFest 2021 10 | 11 |

12 | 13 | ## Event details : 14 | 15 | - Hacktoberfest® is open to everyone in our global community. Whether you’re a developer, student learning to code, event host, or company of any size, you can help drive growth of open source and make positive contributions to an ever-growing community. All backgrounds and skill levels are encouraged to complete the challenge. 16 | 17 | - Hacktoberfest is a celebration open to everyone in our global community. 18 | - Pull requests can be made in any GitHub-hosted repositories/projects. 19 | - You can sign up anytime between October 1 and October 31. 20 | 21 | ## HacktoberFest Rules : 22 | 23 | To earn your Hacktoberfest tee or tree reward, you must register and make four valid pull requests (PRs) between October 1-31 (in any time zone). Pull requests can be made in any participating GitHub or GitLab hosted repository/project. Look for the 'hacktoberfest' topic to know if a repository/project is participating in Hacktoberfest. Pull requests must be approved by a maintainer of the repository/project to count. If a maintainer reports your pull request as spam or behavior not in line with the project’s code of conduct, you will be ineligible to participate. This year, the first 55,000 participants who successfully complete the challenge will be eligible to receive a prize. 24 | *** 25 |

Whether it’s your 1st or 10th pull request, there’s always more to learn! We’ve put together a few resources that can help you create quality pull requests, keep your repositories pristine, and build on your open source knowledge.

26 | 27 | *** 28 | 29 |

30 | 31 | Join Discord Conversation 32 | 33 |

34 | 35 | *** 36 | ## Rules To Contribute To This Repo 37 | - 38 | Code of Conduct 39 | 40 | - 41 | Contribution Guidelines 42 | 43 | 44 | ## Steps For Contribution 45 | 46 | 1. Fork this repo 47 | 2. Star this repo 48 | 3. Add a file 49 | 4. commit the code 50 | 5. Make pull request 51 | *** 52 |

53 |

54 | Thank You 55 |

56 |

57 | -------------------------------------------------------------------------------- /RemoveDuplicates.cpp: -------------------------------------------------------------------------------- 1 | // C++ program to remove duplicates in-place 2 | #include 3 | using namespace std; 4 | // Function to remove duplicate elements This function returns new size of modified array. 5 | int removeDuplicates(int arr[], int n) 6 | { 7 | if (n == 0 || n == 1) 8 | return n; 9 | // To store index of next unique element 10 | int j = 0; 11 | // Doing same as done in Method 1 12 | // Just maintaining another updated index i.e. j 13 | for (int i = 0; i < n - 1; i++) 14 | if (arr[i] != arr[i + 1]) 15 | arr[j++] = arr[i]; 16 | 17 | arr[j++] = arr[n - 1]; 18 | return j; 19 | } 20 | // Main Function code 21 | int main() 22 | { 23 | int arr[] = {1, 3, 3, 4, 4, 5,6 , 6, 6}; 24 | int n = sizeof(arr) / sizeof(arr[0]); 25 | // removeDuplicates() returns new size of array. 26 | n = removeDuplicates(arr, n); 27 | // Print updated array 28 | for (int i = 0; i < n; i++) 29 | cout << arr[i] << " "; 30 | return 0; 31 | } 32 | -------------------------------------------------------------------------------- /ShellSort.cpp: -------------------------------------------------------------------------------- 1 | // C++ implementation of Shell Sort 2 | #include 3 | using namespace std; 4 | 5 | // Function to sort array using shellSort 6 | int shellSort(int arr[], int n) 7 | { 8 | // Start with a big gap, then reduce the gap 9 | for (int gap = n/2; gap > 0; gap /= 2) 10 | { 11 | /* Do a gapped insertion sort for this gap size. 12 | The first gap elements a[0..gap-1] are already in gapped order 13 | keep adding one more element until the entire array is 14 | gap sorted */ 15 | for (int i = gap; i < n; i += 1) 16 | { 17 | /*add a[i] to the elements that have been gap sorted 18 | save a[i] in temp and make a hole at position i */ 19 | int temp = arr[i]; 20 | 21 | /*shift earlier gap-sorted elements up until the correct 22 | location for a[i] is found*/ 23 | int j; 24 | for (j = i; j >= gap && arr[j - gap] > temp; j -= gap) 25 | arr[j] = arr[j - gap]; 26 | 27 | // put temp (the original a[i]) in its correct location 28 | arr[j] = temp; 29 | } 30 | } 31 | return 0; 32 | } 33 | 34 | void printArray(int arr[], int n) 35 | { 36 | for (int i=0; i>n; 46 | 47 | int arr[n], i; 48 | cout<<"Enter elements of array\n"; 49 | for(i=0;i>arr[i]; 52 | } 53 | 54 | cout << "Array before sorting: \n"; 55 | printArray(arr, n); 56 | 57 | shellSort(arr, n); 58 | 59 | cout << "Array after sorting: \n"; 60 | printArray(arr, n); 61 | 62 | return 0; 63 | } -------------------------------------------------------------------------------- /TicTacToe.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | using namespace std; 5 | 6 | int currPlayer; 7 | char currSymbol; 8 | 9 | char board[5][5] = {{' ', '|', ' ', '|', ' '}, 10 | {'-', '+', '-', '+', '-'}, 11 | {' ', '|', ' ', '|', ' '}, 12 | {'-', '+', '-', '+', '-'}, 13 | {' ', '|', ' ', '|', ' '}}; 14 | 15 | void drawBoard() 16 | { 17 | for (int i = 0; i < 5; i++) 18 | { 19 | for (int j = 0; j < 5; j++) 20 | { 21 | cout << board[i][j]; 22 | } 23 | cout << "\n"; 24 | } 25 | } 26 | 27 | void addSymbol(char slot) 28 | { 29 | switch (slot) 30 | { 31 | case '1': 32 | board[0][0] = currSymbol; 33 | break; 34 | case '2': 35 | board[0][2] = currSymbol; 36 | break; 37 | case '3': 38 | board[0][4] = currSymbol; 39 | break; 40 | case '4': 41 | board[2][0] = currSymbol; 42 | break; 43 | case '5': 44 | board[2][2] = currSymbol; 45 | break; 46 | case '6': 47 | board[2][4] = currSymbol; 48 | break; 49 | case '7': 50 | board[4][0] = currSymbol; 51 | break; 52 | case '8': 53 | board[4][2] = currSymbol; 54 | break; 55 | case '9': 56 | board[4][4] = currSymbol; 57 | break; 58 | default: 59 | cout << "Enter a number between 1-9 stupid!" << endl; 60 | break; 61 | } 62 | } 63 | 64 | char checkSymbol(char slot) 65 | { 66 | switch (slot) 67 | { 68 | case '1': 69 | return board[0][0]; 70 | 71 | case '2': 72 | return board[0][2]; 73 | 74 | case '3': 75 | return board[0][4]; 76 | 77 | case '4': 78 | return board[2][0]; 79 | 80 | case '5': 81 | return board[2][2]; 82 | 83 | case '6': 84 | return board[2][4]; 85 | 86 | case '7': 87 | return board[4][0]; 88 | 89 | case '8': 90 | return board[4][2]; 91 | 92 | case '9': 93 | return board[4][4]; 94 | 95 | default: 96 | return '#'; 97 | } 98 | } 99 | 100 | int checkWinner() 101 | { 102 | for (int i = 0; i < 3; i++) 103 | { 104 | if(board[2*i][0]!= ' ') { 105 | if ((board[2*i][0] == board[2*i][2]) && (board[2*i][0] == board[2*i][4])) 106 | { 107 | cout << "Player " << currPlayer << " wins! Yay!\n"; 108 | return currPlayer; 109 | } 110 | } 111 | } 112 | 113 | for (int i = 0; i < 3; i++) 114 | { 115 | if(board[0][2*i]!=' ') { 116 | if ((board[0][2 * i] == board[2][2 * i]) && (board[0][2 * i] == board[4][2 * i])) 117 | { 118 | cout << "Player " << currPlayer << " wins! Yay!\n"; 119 | return currPlayer; 120 | } 121 | } 122 | } 123 | 124 | if(board[0][0]!=' ') { 125 | if ((board[0][0] == board[2][2]) && (board[0][0] == board[4][4])) 126 | { 127 | cout << "Player " << currPlayer << " wins! Yay!\n"; 128 | return currPlayer; 129 | } 130 | } 131 | 132 | if ((board[0][4] == board[2][2]) && (board[0][4] == board[4][0])) 133 | { 134 | cout << "Player " << currPlayer << " wins! Yay!\n"; 135 | return currPlayer; 136 | } 137 | 138 | return 0; 139 | } 140 | 141 | void game() 142 | { 143 | cout << "Player 1 choose your symbol:" << endl; 144 | char symbol_p1, symbol_p2; 145 | cin >> symbol_p1; 146 | 147 | if(symbol_p1=='X') symbol_p2 = 'O'; 148 | else symbol_p2 = 'X'; 149 | 150 | char slot; 151 | 152 | drawBoard(); 153 | int winner; 154 | 155 | for (int i = 1; i <= 9; i++) 156 | { 157 | if (i % 2 == 1) 158 | { 159 | currPlayer = 1; 160 | currSymbol = symbol_p1; 161 | cout << "Player " << currPlayer << " choose your slot\n"; 162 | cin >> slot; 163 | if (checkSymbol(slot) != ' ') 164 | { 165 | cout << "Slot already taken\n"; 166 | i--; 167 | continue; 168 | } 169 | addSymbol(slot); 170 | } 171 | else 172 | { 173 | currPlayer = 2; 174 | currSymbol = symbol_p2; 175 | cout << "Player " << currPlayer << " choose your slot\n"; 176 | cin >> slot; 177 | if (checkSymbol(slot) != ' ') 178 | { 179 | cout << "Slot already taken\n"; 180 | i--; 181 | continue; 182 | } 183 | addSymbol(slot); 184 | } 185 | drawBoard(); 186 | winner = checkWinner(); 187 | if (winner == 1 || winner == 2) 188 | { 189 | return; 190 | } 191 | } 192 | } 193 | 194 | void gameVsCpu() 195 | { 196 | cout << "Player 1 choose your symbol: (X or O are the symbols as decided by the Universal Tic Tac Toe association" << endl; 197 | char symbol_p1, symbol_p2; 198 | cin >> symbol_p1; 199 | 200 | if (symbol_p1 == 'X'||symbol_p1=='x') 201 | symbol_p2 = 'O'; 202 | else 203 | symbol_p2 = 'X'; 204 | 205 | char slot; 206 | 207 | drawBoard(); 208 | int winner; 209 | 210 | for (int i = 1; i <= 9; i++) 211 | { 212 | if (i % 2 == 1) 213 | { 214 | currPlayer = 1; 215 | currSymbol = symbol_p1; 216 | cout << "Player " << currPlayer << " choose your slot\n"; 217 | cin >> slot; 218 | if (checkSymbol(slot) != ' ') 219 | { 220 | cout << "Slot already taken\n"; 221 | i--; 222 | continue; 223 | } 224 | addSymbol(slot); 225 | } 226 | else 227 | { 228 | currPlayer = 2; 229 | currSymbol = symbol_p2; 230 | slot = 49 + rand() % 9; 231 | if (checkSymbol(slot) != ' ') 232 | { 233 | i--; 234 | continue; 235 | } 236 | addSymbol(slot); 237 | 238 | drawBoard(); 239 | } 240 | 241 | winner = checkWinner(); 242 | if (winner == 1 || winner == 2) 243 | { 244 | return; 245 | } 246 | } 247 | } 248 | 249 | int main() 250 | { 251 | srand((unsigned int)time(NULL)); 252 | 253 | drawBoard(); 254 | int input; 255 | cout << "Choose:\n1. If you want to play VS CPU\n2. If you want to play VS player.\n"; 256 | cin >> input; 257 | 258 | if (input == 1) 259 | gameVsCpu(); 260 | else if (input == 2) 261 | game(); 262 | else 263 | cout << "I said choose 1 or 2 you illiterate fuck\n"; 264 | 265 | return 0; 266 | } -------------------------------------------------------------------------------- /TwitterHashtagScrape.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | import tweepy 3 | import json 4 | from tweepy import api 5 | 6 | access_token="" #Add your token 7 | access_token_secret="" #Add your access_token_secret token 8 | 9 | api_key="" #Add your api 10 | api_key_secret="" #Add your api_key_secret token 11 | 12 | auth = tweepy.OAuthHandler(consumer_key=api_key,consumer_secret=api_key_secret) 13 | auth.set_access_token(access_token,access_token_secret) 14 | 15 | api = tweepy.API(auth) 16 | print(api) 17 | 18 | def write_Json(data, filename="hashtag.json"): 19 | with open(filename,"w") as f: 20 | json.dump(data,f,indent=4) 21 | 22 | india_woeid=23424848 # Where On Earth IDentifier 23 | 24 | trend_result=api.trends_place(india_woeid) 25 | 26 | try: 27 | for trend in trend_result[0]["trends"]: 28 | #print(trend["name"]+ " : "+str(trend["tweet_volume"])) #prints all the hashtags with tweet volume 29 | with open ("hashtag.json") as json_data: 30 | data = json.load(json_data) 31 | temp = data["Hashtags"] 32 | y = {"Name":trend["name"]},"volume":str(trend["tweet_volume"]) #Updates to JSON file 33 | temp.append(y) 34 | write_Json(data) 35 | except: 36 | print("Something went wrong") 37 | -------------------------------------------------------------------------------- /URLshortener.py: -------------------------------------------------------------------------------- 1 | # Many times we used to handle urls which have a very 2 | # long length and it is very hard to use it 3 | 4 | # Python provides a cool library in which we can easily shorten our url in a shortcut manner, 5 | # so that it is very handy to use 6 | 7 | # Import the library pyshorteners 8 | import pyshorteners as ps 9 | url = input("Enter The URL: ") 10 | 11 | # The function used to read the url and convert it to a short one 12 | s = ps.Shortener().tinyurl.short(url) 13 | print("The shortened URL is: ", s) 14 | 15 | -------------------------------------------------------------------------------- /VoiceRecorderAPP.py: -------------------------------------------------------------------------------- 1 | # This one got my attention very much 2 | # Building a voice recorder app is very simple than expected using python 3 | 4 | # python provides a very interesting library called sounddevice 5 | # in which the input audio is recorded 6 | 7 | # Using the soundfile library, we can save the recorded voice as FLAC file 8 | import sounddevice as svd 9 | import soundfile as svf 10 | from tkinter import * 11 | 12 | def recored_voice(): 13 | 14 | # Setiing the sampling rate/Frequency to the standard value 15 | fs = 48000 16 | 17 | # We can set the duration of the recording manually by changing this value of the variable 18 | duration = 5 19 | recordingFile = svd.rec(int(duration*fs), samplerate=fs, channels=2) 20 | 21 | svd.wait() 22 | 23 | #save as FLAC file at correct sampling rate 24 | return svf.write('recording.flac', recordingFile, fs) 25 | 26 | 27 | 28 | # Now this part is the main one 29 | # this function is used to design the UI of the application 30 | # its not too much complicated, But just a simple UI 31 | 32 | # Tkinter is mainly used to build the UI and other cool stuff 33 | master = Tk() 34 | 35 | 36 | # Designing the UI 37 | Label(master, text=" Voice Recorder: ").grid(row=0, sticky=W, rowspan=5) 38 | 39 | b = Button(master, text="Start", command=recored_voice) 40 | b.grid(row=0, column=2, columnspan=2, rowspan=2, padx=5, pady=5) 41 | 42 | # Runnung the main loop 43 | mainloop() 44 | 45 | -------------------------------------------------------------------------------- /arithematic-slices.py: -------------------------------------------------------------------------------- 1 | # 413 ARITHEMATIC SLICES 2 | # https://leetcode.com/problems/arithmetic-slices/ 3 | 4 | 5 | # My Approach: 6 | # As I traverse the list, find the lengths of the subarrays which follows the rule c-b == b-a for [...,a,b,c...]. 7 | # And calculate the number of possible combinations thematically. Then continue the same. 8 | 9 | def numberOfArithmeticSlices(nums): 10 | if len(nums) < 3: 11 | return 0 12 | 13 | res, ln = 0, 0 14 | for index in range(2, len(nums)): 15 | if nums[index] - nums[index - 1] == nums[index - 1] - nums[index - 2]: 16 | ln += 3 if ln == 0 else 1 17 | else: 18 | # For len=6, combinations = 19 | # ((6-3)+1) + ((6-4)+1) + ((6-5)+1) + (( 6-6)+1) 20 | total = 0 21 | for i in range(3, ln + 1): 22 | total += ln - i + 1 23 | res += total 24 | ln = 0 25 | 26 | total = 0 27 | for i in range(3, ln + 1): 28 | total += ln - i + 1 29 | res += total 30 | 31 | return res 32 | 33 | 34 | nums = [1,2,3,4] 35 | ans = numberOfArithmeticSlices(nums) 36 | print(ans) 37 | # 38 | # Example 39 | # 1: 40 | # 41 | # Input: nums = [1, 2, 3, 4] 42 | # Output: 3 43 | # Explanation: We have 3 arithmetic slices in nums: [1, 2, 3], [2, 3, 4] and [1, 2, 3, 4] itself. 44 | 45 | # Example 46 | # 2: 47 | # 48 | # Input: nums = [1] 49 | # Output: 0 50 | -------------------------------------------------------------------------------- /binarySearch.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int binarySearch(int *arr, int n, int k) { 5 | int start = 0, end = n - 1; 6 | 7 | while(start <= end) { 8 | int mid = (start + end) / 2; 9 | 10 | if(arr[mid] == k) { 11 | return mid; 12 | } 13 | else if(arr[mid] < k) { 14 | start = mid + 1; 15 | } 16 | else { 17 | end = mid - 1; 18 | } 19 | } 20 | 21 | return -1; 22 | } 23 | 24 | int main() { 25 | int n; 26 | cin >> n; 27 | 28 | int *arr = new int[n]; 29 | 30 | for(int i = 0; i < n; i++) { 31 | cin >> arr[i]; 32 | } 33 | 34 | int k; 35 | cin >> k; 36 | 37 | int i = binarySearch(arr, n, k); 38 | 39 | if(i != -1) { 40 | cout << "Element found at index " << i << endl; 41 | } 42 | 43 | else { 44 | cout << "Element not found" << endl; 45 | } 46 | 47 | delete [] arr; 48 | } -------------------------------------------------------------------------------- /bitsinnumber.py: -------------------------------------------------------------------------------- 1 | # count total number of bits in a number 2 | 3 | # declare a number 4 | num = 61 5 | 6 | # use bin () method to get the binary value of a number 7 | # print binary value output will be 0b111101 8 | print("binary value of {0} is: {1}".format (num, bin(num))) 9 | 10 | # store the length of the binary number 11 | length = len(bin(num)) 12 | 13 | # since binary value contains 0b as prefix 14 | # so to get exact length total number of bits 15 | # subtract 2 from the length 16 | length -=2 17 | 18 | # print length 19 | print("total number of bits: ", length) 20 | -------------------------------------------------------------------------------- /bubble-sort.cpp: -------------------------------------------------------------------------------- 1 | //Ishita Karandikar 2 | // C++ program for implementation of Bubble sort 3 | #include 4 | using namespace std; 5 | 6 | void swap(int *x, int *y) 7 | { 8 | int temp = *x; 9 | *x = *y; 10 | *y = temp; 11 | } 12 | 13 | // A function to implement bubble sort 14 | void bubbleSort(int arr[], int n) 15 | { 16 | int i, j; 17 | for (i = 0; i < n-1; i++) 18 | 19 | // Last i elements are already in place 20 | for (j = 0; j < n-i-1; j++) 21 | if (arr[j] > arr[j+1]) 22 | swap(&arr[j], &arr[j+1]); 23 | } 24 | 25 | /* Function to print an array */ 26 | void printArray(int arr[], int size) 27 | { 28 | int i; 29 | for (i = 0; i < size; i++) 30 | cout << arr[i] << " "; 31 | cout << endl; 32 | } 33 | 34 | // Driver code 35 | int main() 36 | { 37 | int arr[] = {64, 34, 25, 12, 22, 11, 90}; 38 | int n = sizeof(arr)/sizeof(arr[0]); 39 | bubbleSort(arr, n); 40 | cout<<"Sorted array: \n"; 41 | printArray(arr, n); 42 | return 0; 43 | } 44 | -------------------------------------------------------------------------------- /bucketsort.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include //used for the sake of simplicity 4 | using namespace std; 5 | 6 | void bucketSort(float arr[], int n) 7 | { 8 | vector b[n]; 9 | 10 | for (int i=0; i>n; 26 | float arr[n]; 27 | 28 | for (int i=0; i> arr[i]; 31 | } 32 | bucketSort(arr, n); 33 | 34 | cout << "\nAfter Sorting \n"; 35 | for (int i=0; i= d[i]) { 26 | minimum = min(minimum, 1+M[j-d[i]]); 27 | } 28 | } 29 | M[j] = minimum; 30 | } 31 | return M[n]; 32 | } 33 | 34 | public static void main(String[] args) { 35 | // array starting from 1, element at index 0 is fake 36 | int d[] = {0, 1, 2, 3}; 37 | System.out.println(coinChange(d, 5, 3)); //to make 5. Number of denominations = 3 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /contribute.md: -------------------------------------------------------------------------------- 1 | ## Contributing 2 | 3 | Hey there! We're thrilled that you'd like to contribute to this project. Your help is essential for keeping it great. 4 | 5 | Please note that this project is released with a [Contributor Code of Conduct](https://github.com/srinidh-007/HackotberFest2021/blob/main/CODE_OF_CONDUCT.md). By participating in this project you agree to abide by its terms. 6 | 7 | # Rules & Regulations 8 | 9 | - Use any language. 10 | - Don't spam it will be rejected immediately 11 | - Python, C, C++, Java, Docker, JavaScript, Node, Data Structure and Algorithms, HTML, CSS, WebDev, Android Projects are Encouraged 12 | - Anything valuable for Community 13 | - Please check for the file your contributing is already available or not if it is available contribute something new, duplicate content will be -rejected immediately 14 | 15 | ## Issues and PRs 16 | 17 | This is a beginner friendly repository where all those people who are new to open source can contribute. 18 | The unique thing is you can use any language of your choice be it Python, C, C++, Java or useful projects written in HTML, CSS, JavaScript, Node, Data Structure and Algorithms, Android Projects which would be considered valuable to the open source community as a whole. Interested? See the #how to contribute. 19 | 20 | ## How to Contribute 21 | 22 | - Take a look at the Existing [Issues](https://github.com/srinidh-007/HackotberFest2021.git) or create your own Prs with any language! 23 | - Fork the Repo so that you have a local copy then clone it into your PC. 24 | - Create a Pull Request which will be promptly reviewed and suggestions would be added to improve it. 25 | 26 | ## How to make a Pull Request 27 | 28 | **1.** Fork the repository by clicking on the symbol at the top right corner. 29 | 30 | **2.** Clone the forked repository. 31 | ``` 32 | git clone https://github.com/srinidh-007/HackotberFest2021.git 33 | ``` 34 | 35 | **3.** Make changes in source code using any code editor. 36 | 37 | **4.** Stage your changes and commit 38 | 39 | ``` 40 | git add . 41 | ``` 42 | 43 | ``` 44 | git commit -m "" 45 | ``` 46 | 47 | **5.** Push your local commits to the remote repo. 48 | 49 | ``` 50 | git push 51 | ``` 52 | 53 | **6.** Create a [PR](https://help.github.com/en/github/collaborating-with-issues-and-pull-requests/creating-a-pull-request) 54 | 55 | ## Resources 56 | 57 | - [How to Contribute to Open Source](https://opensource.guide/how-to-contribute/) 58 | - [Using Pull Requests](https://help.github.com/articles/about-pull-requests/) 59 | - [GitHub Help](https://help.github.com) 60 | -------------------------------------------------------------------------------- /decimal_to_binary.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | echo -n "Enter a number: " 3 | read -r binary 4 | if [ "$binary" -eq 0 ]; then 5 | echo "Enter a valid number " 6 | return 7 | else 8 | while [ "$binary" -ne 0 ]; do 9 | decimal=0 10 | power=1 11 | while [ "$binary" -ne 0 ]; do 12 | rem=$((binary % 10)) 13 | decimal=$((decimal + (rem * power))) 14 | power=$((power * 2)) 15 | binary=$((binary / 10)) 16 | done 17 | echo " $decimal" 18 | done 19 | fi 20 | -------------------------------------------------------------------------------- /hands on loops and if-else in python.py: -------------------------------------------------------------------------------- 1 | # simple calculator program 2 | def cal(result,val,operator): 3 | if(operator=='+'): 4 | return result+val 5 | elif(operator=='-'): 6 | return result-val 7 | elif(operator=='*'): 8 | return result*val 9 | elif(operator=='/'): 10 | return result/val 11 | print("#############") 12 | operator = '+' 13 | val1 = int(input("Enter the value1")) 14 | result = val1 15 | operator = input("enter the operation you want to perform") 16 | val2 = int(input("Enter the value2")) 17 | result=cal(result,val2,operator) 18 | while(operator!='='): 19 | operator = input("enter the operation you want to perform") 20 | if(operator!='='): 21 | value = int(input("Enter value to be performed for operation")) 22 | result=cal(result,value,operator) 23 | print("#############") 24 | print(f"Result:{result}") 25 | -------------------------------------------------------------------------------- /heap_sort.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | // To heapify a subtree rooted with node i which is 6 | // an index in arr[]. n is size of heap 7 | void heapify(int arr[], int n, int i) 8 | { 9 | int largest = i; // Initialize largest as root 10 | int l = 2 * i + 1; // left = 2*i + 1 11 | int r = 2 * i + 2; // right = 2*i + 2 12 | 13 | // If left child is larger than root 14 | if (l < n && arr[l] > arr[largest]) 15 | largest = l; 16 | 17 | // If right child is larger than largest so far 18 | if (r < n && arr[r] > arr[largest]) 19 | largest = r; 20 | 21 | // If largest is not root 22 | if (largest != i) { 23 | swap(arr[i], arr[largest]); 24 | 25 | // Recursively heapify the affected sub-tree 26 | heapify(arr, n, largest); 27 | } 28 | } 29 | 30 | // main function to do heap sort 31 | void heapSort(int arr[], int n) 32 | { 33 | // Build heap (rearrange array) 34 | for (int i = n / 2 - 1; i >= 0; i--) 35 | heapify(arr, n, i); 36 | 37 | // One by one extract an element from heap 38 | for (int i = n - 1; i > 0; i--) { 39 | // Move current root to end 40 | swap(arr[0], arr[i]); 41 | 42 | // call max heapify on the reduced heap 43 | heapify(arr, i, 0); 44 | } 45 | } 46 | 47 | /* A utility function to print array of size n */ 48 | void printArray(int arr[], int n) 49 | { 50 | for (int i = 0; i < n; ++i) 51 | cout << arr[i] << " "; 52 | cout << "\n"; 53 | } 54 | 55 | // Driver code 56 | int main() 57 | { 58 | int arr[] = { 12, 11, 13, 5, 6, 7 }; 59 | int n = sizeof(arr) / sizeof(arr[0]); 60 | 61 | heapSort(arr, n); 62 | 63 | cout << "Sorted array is \n"; 64 | printArray(arr, n); 65 | } -------------------------------------------------------------------------------- /implement_trie.py: -------------------------------------------------------------------------------- 1 | # we are creating Trie Data Structure and implementing various methods of the Data Structure 2 | class TrieNode: 3 | def __init__(self, val): 4 | self.val = val 5 | self.isEnd = False 6 | self.children = [None for i in range(26)] 7 | class Trie: 8 | def __init__(self): 9 | """ 10 | Initialize your data structure here. 11 | """ 12 | self.root = TrieNode('*') 13 | 14 | 15 | def insert(self, word: str) -> None: 16 | """ 17 | Inserts a word into the trie. 18 | """ 19 | node = self.root 20 | for c in word: 21 | x = ord(c) - ord('a') 22 | if node.children[x] is None: 23 | node.children[x] = TrieNode(c) 24 | node = node.children[x] 25 | node.isEnd = True 26 | 27 | def search(self, word: str) -> bool: 28 | """ 29 | Returns if the word is in the trie. 30 | """ 31 | node = self.root 32 | for c in word: 33 | x = ord(c) - ord('a') 34 | if node.children[x] is not None: 35 | node = node.children[x] 36 | else: 37 | return False 38 | return node.isEnd 39 | 40 | 41 | def startsWith(self, prefix: str) -> bool: 42 | """ 43 | Returns if there is any word in the trie that starts with the given prefix. 44 | """ 45 | node = self.root 46 | for c in prefix: 47 | x = ord(c) - ord('a') 48 | if node.children[x] is not None: 49 | node = node.children[x] 50 | else: 51 | return False 52 | return True -------------------------------------------------------------------------------- /jump_search.cpp: -------------------------------------------------------------------------------- 1 | // including header files 2 | #include 3 | #include 4 | // namespace std 5 | using namespace std; 6 | // main function 7 | int main(){ 8 | // integer for taking input of number of elements in array 9 | int n; 10 | // instruction to take input 11 | cout<<"Enter the number of elements: "; 12 | // taking input 13 | cin>>n; 14 | // instruction to take elements in the array 15 | cout<<"Enter the elements in the sorted order: "; 16 | // initializing the array of length n 17 | int a[n]; 18 | // for loop to take input array 19 | for(int i=0;i>a[i]; 21 | } 22 | // d variable will store the array element to be searched 23 | int d; 24 | cout<<"Enter the element to search: "; 25 | cin>>d; 26 | // the skip count will be stored in x and i is for iteration in the array 27 | int x,i; 28 | // preferred skip count is considered as square root of the length of array 29 | cout<<"Enter the skip count: (Preferred: "<>x; 31 | // searching the element by skipping the count by x indices 32 | for(i=0;id){ 35 | break; 36 | } 37 | } 38 | // from current index to the next jumped index, each element is checked and if found, that index is printed else a message is printed saying not found 39 | for(int t=i;t List[int]: 4 | if len(nums) < 2: 5 | return nums 6 | 7 | #creating a monotonic sequence of list 8 | nums.sort() 9 | 10 | dp = [1]*len(nums) 11 | max_ind = 0 12 | 13 | #dp pass using the following condition 14 | for i in range(1, len(nums)): 15 | for j in range(i): 16 | if nums[i]%nums[j] == 0: 17 | dp[i] = max(dp[i], dp[j] + 1) 18 | if dp[max_ind] < dp[i]: 19 | max_ind = i 20 | 21 | res = [] 22 | res.append(nums[max_ind]) 23 | 24 | prev = nums[max_ind] 25 | 26 | #reconstructing the sequence by iterating backwards 27 | for i in range(max_ind - 1, -1, -1): 28 | if dp[i] > 0 and dp[max_ind]-1 == dp[i] and prev%nums[i] == 0: 29 | res.append(nums[i]) 30 | prev = nums[i] 31 | max_ind = i 32 | 33 | res.reverse() 34 | return res -------------------------------------------------------------------------------- /longest_common_subsequence.java: -------------------------------------------------------------------------------- 1 | /* A Naive recursive implementation of LCS problem in java*/ 2 | 3 | public class LongestCommonSubsequence 4 | { 5 | 6 | /* Returns length of LCS for X[0..m-1], Y[0..n-1] */ 7 | int lcs( char[] X, char[] Y, int m, int n ) 8 | { 9 | if (m == 0 || n == 0) 10 | return 0; 11 | if (X[m-1] == Y[n-1]) 12 | return 1 + lcs(X, Y, m-1, n-1); 13 | else 14 | return max(lcs(X, Y, m, n-1), lcs(X, Y, m-1, n)); 15 | } 16 | 17 | /* Utility function to get max of 2 integers */ 18 | int max(int a, int b) 19 | { 20 | return (a > b)? a : b; 21 | } 22 | 23 | public static void main(String[] args) 24 | { 25 | LongestCommonSubsequence lcs = new LongestCommonSubsequence(); 26 | String s1 = "AGGTAB"; 27 | String s2 = "GXTXAYB"; 28 | 29 | char[] X=s1.toCharArray(); 30 | char[] Y=s2.toCharArray(); 31 | int m = X.length; 32 | int n = Y.length; 33 | 34 | System.out.println("Length of LCS is" + " " + 35 | lcs.lcs( X, Y, m, n ) ); 36 | } 37 | 38 | } 39 | 40 | 41 | -------------------------------------------------------------------------------- /merge sort.py: -------------------------------------------------------------------------------- 1 | # Python program to count inversions in an array 2 | 3 | # Function to Use Inversion Count 4 | def mergeSort(arr, n): 5 | # A temp_arr is created to store 6 | # sorted array in merge function 7 | temp_arr = [0] * n 8 | return _mergeSort(arr, temp_arr, 0, n - 1) 9 | 10 | 11 | # This Function will use MergeSort to count inversions 12 | 13 | def _mergeSort(arr, temp_arr, left, right): 14 | # A variable inv_count is used to store 15 | # inversion counts in each recursive call 16 | 17 | inv_count = 0 18 | 19 | # We will make a recursive call if and only if 20 | # we have more than one elements 21 | 22 | if left < right: 23 | # mid is calculated to divide the array into two subarrays 24 | # Floor division is must in case of python 25 | 26 | mid = (left + right) // 2 27 | 28 | # It will calculate inversion counts in the left subarray 29 | 30 | inv_count += _mergeSort(arr, temp_arr, left, mid) 31 | 32 | # It will calculate inversion counts in right subarray 33 | 34 | inv_count += _mergeSort(arr, temp_arr, mid + 1, right) 35 | 36 | # It will merge two subarrays in a sorted subarray 37 | 38 | inv_count += merge(arr, temp_arr, left, mid, right) 39 | return inv_count 40 | 41 | 42 | # This function will merge two subarrays in a single sorted subarray 43 | def merge(arr, temp_arr, left, mid, right): 44 | i = left # Starting index of left subarray 45 | j = mid + 1 # Starting index of right subarray 46 | k = left # Starting index of to be sorted subarray 47 | inv_count = 0 48 | 49 | # Conditions are checked to make sure that i and j don't exceed their 50 | # subarray limits. 51 | 52 | while i <= mid and j <= right: 53 | 54 | # There will be no inversion if arr[i] <= arr[j] 55 | 56 | if arr[i] <= arr[j]: 57 | temp_arr[k] = arr[i] 58 | k += 1 59 | i += 1 60 | else: 61 | # Inversion will occur. 62 | temp_arr[k] = arr[j] 63 | inv_count += (mid - i + 1) 64 | k += 1 65 | j += 1 66 | 67 | # Copy the remaining elements of left subarray into temporary array 68 | while i <= mid: 69 | temp_arr[k] = arr[i] 70 | k += 1 71 | i += 1 72 | 73 | # Copy the remaining elements of right subarray into temporary array 74 | while j <= right: 75 | temp_arr[k] = arr[j] 76 | k += 1 77 | j += 1 78 | 79 | # Copy the sorted subarray into Original array 80 | for loop_var in range(left, right + 1): 81 | arr[loop_var] = temp_arr[loop_var] 82 | 83 | return inv_count 84 | 85 | 86 | # Driver Code 87 | # Given array is 88 | arr = [1, 20, 6, 4, 5] 89 | n = len(arr) 90 | result = mergeSort(arr, n) 91 | print("Number of inversions are", result) 92 | -------------------------------------------------------------------------------- /min_cost_path.java: -------------------------------------------------------------------------------- 1 | /* A Naive recursive implementation of 2 | MCP(Minimum Cost Path) problem */ 3 | public class GFG { 4 | 5 | /* A utility function that returns 6 | minimum of 3 integers */ 7 | static int min(int x, int y, int z) 8 | { 9 | if (x < y) 10 | return (x < z) ? x : z; 11 | else 12 | return (y < z) ? y : z; 13 | } 14 | 15 | /* Returns cost of minimum cost path 16 | from (0,0) to (m, n) in mat[R][C]*/ 17 | static int minCost(int cost[][], int m, 18 | int n) 19 | { 20 | if (n < 0 || m < 0) 21 | return Integer.MAX_VALUE; 22 | else if (m == 0 && n == 0) 23 | return cost[m][n]; 24 | else 25 | return cost[m][n] + 26 | min( minCost(cost, m-1, n-1), 27 | minCost(cost, m-1, n), 28 | minCost(cost, m, n-1) ); 29 | } 30 | 31 | // Driver code 32 | public static void main(String args[]) 33 | { 34 | 35 | int cost[][] = { {1, 2, 3}, 36 | {4, 8, 2}, 37 | {1, 5, 3} }; 38 | 39 | System.out.print(minCost(cost, 2, 2)); 40 | } 41 | } 42 | 43 | 44 | -------------------------------------------------------------------------------- /non-overlapping-intervals.py: -------------------------------------------------------------------------------- 1 | # 435. Non-overlapping Intervals 2 | # https://leetcode.com/problems/non-overlapping-intervals 3 | 4 | def eraseOverlapIntervals(intervals): 5 | if not intervals: 6 | return 0 7 | intervals.sort() 8 | count = 0 9 | 10 | new_interval = intervals[0] 11 | for i in range(1, len(intervals)): 12 | if intervals[i][0] < new_interval[1]: 13 | count += 1 14 | new_interval = [min(new_interval[0], intervals[i][0]), 15 | min(new_interval[1], intervals[i][1])] 16 | else: 17 | new_interval = intervals[i] 18 | return count 19 | 20 | 21 | 22 | 23 | list = [[1,2],[2,3],[3,4],[1,3]] 24 | ans = eraseOverlapIntervals(list) 25 | print(ans) 26 | 27 | 28 | 29 | # Example 1: 30 | # 31 | # Input: intervals = [[1,2],[2,3],[3,4],[1,3]] 32 | # Output: 1 33 | # Explanation: [1,3] can be removed and the rest of the intervals are non-overlapping. 34 | # Example 2: 35 | # 36 | # Input: intervals = [[1,2],[1,2],[1,2]] 37 | # Output: 2 38 | # Explanation: You need to remove two [1,2] to make the rest of the intervals non-overlapping. 39 | # Example 3: 40 | # 41 | # Input: intervals = [[1,2],[2,3]] 42 | # Output: 0 43 | # Explanation: You don't need to remove any of the intervals since they're already non-overlapping. 44 | -------------------------------------------------------------------------------- /password-suggester.py: -------------------------------------------------------------------------------- 1 | import random 2 | 3 | 4 | def insert(s, pos, ch): 5 | return(s[:pos] + ch + s[pos:]) 6 | 7 | 8 | def add_more_char(s, need): 9 | pos = 0 10 | 11 | # add 26 letters 12 | low_case = "abcdefghijklmnopqrstuvwxyz" 13 | 14 | for i in range(need): 15 | pos = random.randint(0, len(s)-1) 16 | s = insert(s, pos, low_case[random.randint(0,25)]) 17 | 18 | return(s) 19 | 20 | 21 | def suggester(l, u, d, s, st): 22 | 23 | 24 | num = '0123456789' 25 | 26 | 27 | low_case = "abcdefghijklmnopqrstuvwxyz" 28 | up_case = low_case.upper() 29 | spl_char = '@#$_()!' 30 | 31 | 32 | pos = 0 33 | 34 | 35 | if( l == 0 ): 36 | 37 | 38 | pos = random.randint(0,len(st)-1) 39 | 40 | 41 | st = insert(st, pos, low_case[random.randint(0,25)]) 42 | 43 | 44 | if( u == 0 ): 45 | 46 | 47 | pos = random.randint(0,len(st)-1) 48 | 49 | 50 | st = insert(st, pos, up_case[random.randint(0,25)]) 51 | 52 | 53 | if( d == 0 ): 54 | 55 | 56 | pos = random.randint(0,len(st)-1) 57 | 58 | 59 | st = insert(st, pos, num[random.randint(0,9)]) 60 | 61 | 62 | 63 | if( s == 0 ): 64 | 65 | 66 | pos = random.randint(0,len(st)-1) 67 | 68 | 69 | st = insert(st, pos, low_case[random.randint(0,6)]) 70 | 71 | return st 72 | 73 | 74 | def generate_password(n, p): 75 | 76 | 77 | l = 0; u = 0; d = 0; s = 0; need = 0 78 | 79 | 80 | suggest = '' 81 | 82 | for i in range(n): 83 | 84 | 85 | if( p[i].islower() ): 86 | l = 1 87 | elif( p[i].isupper() ): 88 | u = 1 89 | elif( p[i].isdigit() ): 90 | d = 1 91 | else: 92 | s = 1 93 | 94 | 95 | if( (l + u + d + s) == 4): 96 | print("Your Password is Strong") 97 | return 98 | else: 99 | print("Suggested Passwords") 100 | 101 | 102 | for i in range(10): 103 | suggest = suggester(l, u, d, s, p) 104 | need = 8 - len(suggest) 105 | 106 | if(need > 0): 107 | suggest = add_more_char(suggest, need) 108 | print(suggest) 109 | 110 | 111 | 112 | input_string = 'hacktoberfest@2021' 113 | 114 | generate_password( len(input_string), input_string) 115 | -------------------------------------------------------------------------------- /rand_func.c: -------------------------------------------------------------------------------- 1 | /*#include 2 | #include 3 | #include 4 | // Generates and prints 'count' random 5 | // numbers in range [L, U]. 6 | void printRandoms(int L, int U, int count) 7 | { 8 | int i; 9 | for (i = 0; i < count; i++) { 10 | int num=(rand()%(U-L+1))+L; 11 | printf("%d ",num); 12 | } 13 | } 14 | // Driver code 15 | int main() 16 | { 17 | int L = 0, U = 49, count = 5; 18 | // Use current time as 19 | // seed for random generator 20 | srand(time(0)); 21 | printRandoms(L, U, count); 22 | return 0; 23 | } 24 | */ 25 | -------------------------------------------------------------------------------- /rock_paper_scissor.java: -------------------------------------------------------------------------------- 1 | // this is a rock paper scissor command line game 2 | 3 | import java.util.Scanner; 4 | import java.util.Random; 5 | 6 | class rpsgame{ 7 | public static void main(String args[] ) { 8 | System.out.println("\n this is rock scissor paper game \n enter 113 to quit the game after every chance \n every player will get a chance \n so lets begin\n") ; 9 | Random jj = new Random(); 10 | Scanner ss = new Scanner(System.in); 11 | // System.out.println(jj.nextInt(3)); 12 | int compscore=0 , compchoice , userscore=0; 13 | int i = jj.nextInt(2); 14 | while(i!=113) { 15 | System.out.println("user enter your input press|| 0 for rock || 1 for paper || 2 for scissor \n"); 16 | i = ss.nextInt(); 17 | if(i==113) { 18 | break; 19 | } 20 | if(i<0||i>2) { 21 | System.out.println("enter correct input \n"); 22 | i = ss.nextInt(); 23 | } 24 | compchoice = jj.nextInt(2); 25 | System.out.println("compchoice " + compchoice + "\n"); 26 | if(compchoice==i) { 27 | System.out.println("\ndraw\n"); 28 | } 29 | else if((compchoice==0)&&(i==1)) { 30 | i++; 31 | System.out.println("\nuser wins this turn\n"); 32 | } 33 | else if((compchoice==0)&&(i==2)) { 34 | compscore++; 35 | System.out.println("\ncomp wins this turn\n"); 36 | } 37 | else if((compchoice==1)&&(i==0)) { 38 | compscore++; 39 | System.out.println("\ncomp wins this turn\n"); 40 | } 41 | else if((compchoice==1)&&(i==2)) { 42 | i++; 43 | System.out.println("\nuser wins this turn\n"); 44 | } 45 | else if((compchoice==2)&&(i==0)) { 46 | i++; 47 | System.out.println("\nuser wins this turn\n"); 48 | } 49 | else if((compchoice==2)&&(i==1)) { 50 | compscore++; 51 | System.out.println("\ncomp wins this turn\n"); 52 | } 53 | userscore = i; 54 | } 55 | System.out.print("\nfinal scores are\nuser : " + userscore + "\ncomp : " + compscore + "\n winner is : " ); 56 | if(userscore>compscore) { 57 | System.out.println("user\n"); 58 | } 59 | else if(userscore 2 | #include 3 | 4 | using namespace std; 5 | 6 | /* 7 | a function which returns false when a character belongs to Roman literals else returns true 8 | */ 9 | bool is_roman(char x){ 10 | return !(x=='I' || x=='V' || x=='X' || x=='L' || x=='C' || x=='D' || x=='M'); 11 | } 12 | 13 | /* 14 | Roman to Numerical convert function 15 | */ 16 | int main(int argc,char* argv[]){ 17 | //condition to check null input 18 | if(argv[1]==NULL){ 19 | cerr<<"Usage: please provide a string of roman numerals"< value; 37 | value['I']=1; 38 | value['V']=5; 39 | value['X']=10; 40 | value['L']=50; 41 | value['C']=100; 42 | value['D']=500; 43 | value['M']=1000; 44 | 45 | //variable to store the value 46 | int num=0; 47 | 48 | for(int i=s.size()-1;i>=0;i--){ 49 | //To handle cases like IV where it should be considered as 4 50 | if(value[s[i]]>value[s[i-1]] && i>0){ 51 | num+=value[s[i]]-value[s[i-1]]; 52 | i--; 53 | }else{ 54 | num+=value[s[i]]; 55 | } 56 | } 57 | 58 | cout< 4 | 5 | using namespace std; 6 | 7 | void seive(int n){ 8 | bool primes[n+1]; 9 | for(int i = 2; i*i <= n;i++){ 10 | if(!primes[i]){ 11 | for(int j = i*2 ; j <= n; j+=i){ 12 | primes[j] = true; 13 | } 14 | } 15 | } 16 | for(int i = 2; i <= n; i++){ 17 | if(!primes[i]){ 18 | cout<>n; 26 | seive(n); 27 | } 28 | 29 | 30 | // Time complexity of this algorithm is O(n*log(logn)). 31 | 32 | // We are looking at N/2 + N/3 + N/5 + N/7 + .........N/P p<=sqrt(n). -------------------------------------------------------------------------------- /selection_sort.py: -------------------------------------------------------------------------------- 1 | ''' 2 | Sorting: Selection sort using recursion 3 | ''' 4 | 5 | 6 | def selection(l, n): 7 | if n == len(l): 8 | return l 9 | else: 10 | s = max(l) 11 | f = len(l)-1 12 | for i in range(n, len(l)): 13 | if l[i] < s: 14 | s = l[i] 15 | f = i 16 | l[n], l[f] = l[f], l[n] 17 | return selection(l, n+1) 18 | 19 | 20 | f = int(input()) 21 | l = [int(input()) for i in range(f)] 22 | n = 0 23 | print(selection(l, n)) 24 | -------------------------------------------------------------------------------- /stackmain.java: -------------------------------------------------------------------------------- 1 | /** 2 | * stackmain 3 | */ 4 | 5 | 6 | 7 | class stack{ 8 | int top=-1; 9 | int limit = 5; 10 | float array[] = new float[limit]; 11 | 12 | boolean push(float x) 13 | { 14 | if (top >= (limit - 1)) { 15 | System.out.println("Stack Overflow"); 16 | return false; 17 | } 18 | else { 19 | array[++top] = x; 20 | return true; 21 | } 22 | } 23 | 24 | float pop() 25 | { 26 | if (top < 0) { 27 | System.out.println("Stack Underflow"); 28 | return 0; 29 | } 30 | else { 31 | float x = array[top--]; 32 | return x; 33 | } 34 | } 35 | 36 | void display() { 37 | for(int i=top;i>=0;i--) { 38 | System.out.println("| " + array[i] + " "); 39 | } 40 | System.out.println("\n"); 41 | } 42 | 43 | public static void copy(stack s1, stack s2){ 44 | int i; 45 | for(i=0;i<=s1.top;i++) { 46 | s2.array[i] = s1.array[i]; 47 | } 48 | s2.top = s1.top; 49 | } 50 | 51 | } 52 | 53 | 54 | class stackmain { 55 | 56 | 57 | 58 | 59 | public static void main(String[] args) { 60 | stack stack1 = new stack(); 61 | stack stack2 = new stack(); 62 | stack1.push(2.1f); 63 | stack1.push(2.2f); 64 | stack1.push(2.3f); 65 | stack1.pop(); 66 | stack1.push(2.4f); 67 | stack1.pop(); 68 | stack.copy(stack1,stack2); 69 | stack1.display(); 70 | stack2.display(); 71 | } 72 | } -------------------------------------------------------------------------------- /style.css: -------------------------------------------------------------------------------- 1 | * { 2 | padding: 0; 3 | margin: 0; 4 | background-color: powderblue; 5 | } 6 | 7 | .head, 8 | .rules-top { 9 | margin: 50px; 10 | display: flex; 11 | justify-content: center; 12 | align-items: center; 13 | } 14 | 15 | .link { 16 | margin: 50px; 17 | display: flex; 18 | justify-content: center; 19 | align-items: center; 20 | } 21 | 22 | .head h1 { 23 | margin: 50px; 24 | } 25 | 26 | h1, 27 | h2, 28 | h3 { 29 | font-family: "Poppins", sans-serif; 30 | } 31 | 32 | .main { 33 | margin: 50px; 34 | } 35 | .one { 36 | margin-bottom: 20px; 37 | } 38 | -------------------------------------------------------------------------------- /text_to_speech.py: -------------------------------------------------------------------------------- 1 | #Project :Text to speech is a process to convert any text into voice 2 | 3 | 4 | # About project: In this program I have used python 'tkinter' library for rendering graphics on a display window, 'gTTs' (google text to speech) library to convert text to voice, and 'playsound' library to play that converter voice from the text. 5 | 6 | from tkinter import * 7 | From gtts import gTTS 8 | From playsound import playsound 9 | 10 | root = Tk() #Tk() to initialized tkinter which will be used for GUI 11 | geometry root.("350x300") #geometry() used to set the width and height of the window 12 | root.configure(bg='ghost white') #configure() used to access window attributes 13 | root.title("DataFlair - TEXT TO SPEECH") #title() set the title of the window 14 | 15 | 16 | #Label() widget is used to display one or more than one line of text that users can’t able to modify. 17 | 18 | Label(root, text = "TEXT_TO_SPEECH", font = "arial 20 bold", bg='white smoke').pack() # root is the name which we refer to our window 19 | Label(text ="DataFlair", font = 'arial 15 bold', bg ='white smoke' , width = '20').pack(side = 'bottom') 20 | Msg = StringVar() 21 | Label(root,text ="Enter Text", font = 'arial 15 bold', bg ='white smoke').place(x=20,y=60) 22 | entry_field = Entry(root, textvariable = Msg ,width ='50') #Entry() used to create an input text field 23 | entry_field.place(x=20,y=100) 24 | 25 | def Text_to_speech(): 26 | Message = entry_field.get() #Message variable will stores the value of entry_field 27 | 28 | speech = gTTS(text = Message) #speech stores the converted voice from the text 29 | 30 | speech.save('DataFlair.mp3') #speech.save(‘DataFlair.mp3’) will saves the converted file as DataFlair as mp3 file 31 | 32 | playsound('DataFlair.mp3') #playsound() used to play the sound 33 | 34 | #Function to Exit 35 | def Exit(): 36 | root.destroy() 37 | 38 | #Function to Reset 39 | def Reset(): 40 | Msg.set("") 41 | 42 | #Button() widget used to display button on the window 43 | Button(root, text = "PLAY", font = 'arial 15 bold' , command = Text_to_speech ,width = '4').place(x=25,y=140) 44 | Button(root, font = 'arial 15 bold',text = 'EXIT', width = '4' , command = Exit, bg = 'OrangeRed1').place(x=100 , y = 140) 45 | Button(root, font = 'arial 15 bold',text = 'RESET', width = '6' , command = Reset).place(x=175 , y = 140) 46 | 47 | #root.mainloop() is a method that executes when we want to run our program. 48 | root.mainloop() 49 | -------------------------------------------------------------------------------- /transpose_of_sparse_matrix.cpp: -------------------------------------------------------------------------------- 1 | // Transpose of a sparse matrix 2 | 3 | #include 4 | #include 5 | using namespace std; 6 | 7 | int main() { 8 | int row,column,size; 9 | 10 | // input for number of rows and columns and number of non zero elements 11 | cout<<"Enter the number of rows in the matrix: "; 12 | cin>>row; 13 | cout<<"Enter the number of columns in the matrix: "; 14 | cin>>column; 15 | cout<<"Enter the number of non zero elements in the matrix: "; 16 | cin>>size; 17 | 18 | // inputing the matrix in sparse form (triplet form) 19 | if(size <= (row*column)){ 20 | int sparseMatrix[size][3]; 21 | for(int i=0 ; i>sparseMatrix[i][0]; 24 | cin>>sparseMatrix[i][1]; 25 | cin>>sparseMatrix[i][2]; 26 | } 27 | 28 | // Displaying your matrix 29 | cout<<"Your sparse matrix is :\n"; 30 | for(int i=0 ; i 2 | #include 3 | 4 | using namespace std; 5 | 6 | /* 7 | Two Sum will take a n array of numbers and a target as input 8 | and returns the pair of indicies of array which add up to that target 9 | 10 | if such pair doesn't exist, it will simply return an empty array 11 | */ 12 | vector twoSum(vector& nums, int target) { 13 | // a map to store value and it's corresponding index 14 | unordered_map mp; 15 | 16 | // a vector to store final result 17 | vector x; 18 | 19 | // iterating through the array 20 | for (int i = 0; i < nums.size(); i++) { 21 | // check if map contains the target - curr_value 22 | // if yes we found the pair 23 | // else add it to map for referencing further in the array 24 | if (mp.find(target-nums[i]) != mp.end()) { 25 | x.push_back(i); 26 | x.push_back(mp[target-nums[i]]); 27 | break; 28 | } else { 29 | mp[nums[i]] = i; 30 | } 31 | } 32 | 33 | return x; 34 | } 35 | 36 | 37 | /* 38 | Driver code 39 | */ 40 | int main() { 41 | 42 | vector arr; 43 | arr.push_back(1); 44 | arr.push_back(4); 45 | arr.push_back(6); 46 | arr.push_back(3); 47 | arr.push_back(8); 48 | 49 | vector res = twoSum(arr, 10); 50 | cout< 2 | using namespace std; 3 | 4 | // PROBLEM LINK: https://leetcode.com/problems/unique-paths/ 5 | 6 | int uniquePaths(int m, int n) { 7 | vector< vector>dp(m,vector(n)); 8 | for(int i = 0;i=0;i--){ 15 | for(int j = n-2;j>=0;j--){ 16 | dp[i][j]= dp[i+1][j] + dp[i][j+1]; 17 | } 18 | } 19 | 20 | 21 | return dp[0][0]; 22 | } 23 | 24 | int main(){ 25 | 26 | int n; 27 | int m; 28 | n = 3; 29 | n = 2; 30 | //unique paths hsould be 3 31 | //From the top-left corner, there are a total of 3 ways to reach the bottom-right corner: 32 | //1. Right -> Down -> Down 33 | //2. Down -> Down -> Right 34 | //3. Down -> Right -> Down 35 | 36 | cout< 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 13 | 14 | Hacktober2021 15 | 16 | 17 |
18 |

Welcome to Hacktober-fest 2021

19 |
20 | 21 |
22 |

Event Details

23 | 24 |
    25 |
  • 26 | Hacktoberfest® is open to everyone in our global community. Whether 27 | you’re a developer, student learning to code, event host, or company 28 | of any size, you can help drive growth of open source and make 29 | positive contributions to an ever-growing community. All backgrounds 30 | and skill levels are encouraged to complete the challenge. 31 |
  • 32 | 33 |
  • 34 | Hacktoberfest is a celebration open to everyone in our global 35 | community. 36 |
  • 37 | 38 |
  • 39 | Pull requests can be made in any GitHub-hosted repositories/projects. 40 |
  • 41 | 42 |
  • You can sign up anytime between October 1 and October 31.
  • 43 |
44 |
45 | 46 |
47 | 48 |
49 |

Hacktober Rules:

50 |
51 |
52 |

53 | To earn your Hacktoberfest tee or tree reward, you must register and 54 | make four valid pull requests (PRs) between October 1-31 (in any time 55 | zone). Pull requests can be made in any participating GitHub or GitLab 56 | hosted repository/project. Look for the 'hacktoberfest' topic to know if 57 | a repository/project is participating in Hacktoberfest. Pull requests 58 | must be approved by a maintainer of the repository/project to count. If 59 | a maintainer reports your pull request as spam or behavior not in line 60 | with the project’s code of conduct, you will be ineligible to 61 | participate. This year, the first 55,000 participants who successfully 62 | complete the challenge will be eligible to receive a prize. 63 |

64 |
65 |

66 | Whether it’s your 1st or 10th pull request, there’s always more to learn! 67 | We’ve put together a few resources that can help you create quality pull 68 | requests, keep your repositories pristine, and build on your open source 69 | knowledge. 70 |

71 | 72 | 75 | 76 | 77 | --------------------------------------------------------------------------------