├── C++ ├── Sort 0 and 1.cpp ├── reverse_an_array.exe ├── vector-pair │ ├── pair_1.exe │ ├── vector_1.exe │ ├── pair_1.cpp │ └── vector_1.cpp ├── Rotate Array.cpp ├── Climbing Stairs.cpp ├── Find Minimum in Rotated Sorted Array.cpp ├── Pattern printing │ ├── 11Left_Half_Pyramid.cpp │ ├── 1SquareMatrix.cpp │ ├── 20LeftHalf_Inv_Pyramid.cpp │ ├── 13LeftHalfPyramidNumRev.cpp │ ├── 3EqualNumberOfRows.cpp │ ├── 2EqualNumberOfCols.cpp │ ├── 5EqualCCharofRows.cpp │ ├── 14LeftHalfPyramidNumInc.cpp │ ├── 4EqualCharofRows.cpp │ ├── 7EqualCharOfCols.cpp │ ├── 6EqualCCharOfCols.cpp │ ├── 25Full_Pyramid_Inverted.cpp │ ├── 19Full_Pyramid.cpp │ ├── 21MinusMultiplySign.cpp │ ├── 9Pattern.cpp │ ├── 28RightHalf_InvPyramid.cpp │ ├── 8UppLowCharOfRows.cpp │ ├── 26Left-RightHalfPyramid.cpp │ ├── 17Num_Char.cpp │ ├── 10Pattern.cpp │ ├── 16AsteriskDollarlogo.cpp │ ├── 15Left_RightNumbers.cpp │ ├── 29_90D_RotateFullPyd.cpp │ ├── 24FullPyramid_Num.cpp │ ├── 27LR_Half_Char_Pyramid.cpp │ ├── Print_the_Pattern.cpp │ ├── 27RL_Half_CharInvPyd.cpp │ ├── 18Right_Half_Pyramid.cpp │ └── 0-1_Knapsack.cpp ├── Longest Increasing Subsequence.cpp ├── JumpGame.cpp ├── Reverse Pairs.cpp ├── Count digit & Sum of Digit.c ├── Next Permutation.cpp ├── countSort.cpp ├── MoveZeroes.cpp ├── Single_Operation_Part_1.cpp ├── ValidParenthesis.cpp ├── kadane_algorithm.cpp ├── Rod_cutting.cpp ├── towerofhanoi.cpp ├── Trapping Rain Water.cpp ├── Rod_cutting.c ├── insertion sort implementation ├── Dungeon_Game.cpp ├── DistinctSubsequences.cpp ├── length_longest_common_sequence.cpp ├── CountNumberOfText.cpp ├── ContainerWithMostWater.cpp ├── card_removal.cpp ├── reverse_an_array.cpp ├── selection_sort.c ├── 4Sum.cpp ├── heap sort implementation ├── Reverse Nodes in k-Group.cpp ├── Median of Two Sorted Arrays.cpp ├── Book_Allocation_problem.cpp ├── WordSearch.cpp ├── Brick sort.cpp ├── Game of Life.cpp ├── Merge Intervals.cpp ├── spiralordermatrix.cpp ├── Singly_LinkedList.cpp ├── Combination Sum.cpp ├── vertical_order_bt.cpp ├── 3–Partition Problem.cpp ├── Aggressive_Cows.cpp ├── two_pointer_technique.cpp ├── IdenticalTrees.cpp ├── Coin Change.cpp ├── Digital Logarithm.cpp ├── BoxStacking.cpp ├── Reverse_Linked_List_in_a_group_of_size_k.cpp ├── Number of Enclaves.cpp ├── sudokuSolver.cpp ├── anagramSum.cpp ├── countingPairsWithDifferentK.cpp ├── KnightTourProblem.cpp ├── mergelinkedlist.cpp ├── FibonacciSearch.cpp ├── IntervalTree.cpp ├── EERTREEimplementation.cpp ├── Longest Possible Route.cpp └── BtreeImplementation.cpp ├── pascal triangle.cpp ├── StudentReportManagementSystem ├── Faculty.txt ├── Student.txt └── projectImages │ ├── 2.homePage.png │ ├── 1.IntroPage.png │ ├── 23.ExitMenu.png │ ├── 4.adminMenu.png │ ├── 13.FacultyMenu.png │ ├── 18.StudentMenu.png │ ├── 3.LoginAsAdmin.png │ ├── 5.addNewStudent.png │ ├── 8.addNewFaculty.png │ ├── 12.loginAsFaculty.png │ ├── 17.LoginAsStudent.png │ ├── 11.DeleteExistingFaculty.png │ ├── 16.UploadMarksOfStudent.png │ ├── 6.viewExistingStudentDetails.png │ ├── 7.ModifyExistingStudentDetails.png │ ├── 9.viewExistingFacultyDetails.png │ ├── 10.ModifyExistingFacultyDetails.png │ ├── 14.ViewYourProfileFacultySection.png │ ├── 19.viewYourProfileStudentSection.png │ ├── 21.ReviewAndPublishResultAdminSection.png │ ├── 15.viewExistingStudentRecordFacultySection.png │ ├── 22.ResultInStudentSectionAfterAdminPublished.png │ └── 20.ResultSectionWhenFinalResultNotUploadedByAdmin.png ├── Armstong.py ├── JavaScript ├── get_random_data.js ├── README.md ├── use_localstorage.js ├── connectingNodeWithMongoDB.js └── date_manipulation.js ├── If-else statment.cpp ├── opensource ├── pattern.java ├── palindrome.py ├── palindrome.java ├── leapyear.py ├── fibo.java ├── rankthepermutation.py ├── sh.java └── NewYearCountdown.JS ├── linearSearch.cpp ├── Mounted array.cpp ├── Vanya and Lanterns.cpp ├── BubbleSort.cpp ├── Numbers ├── AbundantNumber.java ├── NivenNumbers.java ├── DuckNumbers.java ├── PetersonNumbers.java ├── Magic Number.java ├── HappyNumber.java ├── Disarium.java └── EvilNumbers.java ├── remove_Duplicates_from_Sorted_Array.cpp ├── KnapsackProblem.cpp ├── Palindrome_Partitioning.cpp ├── H_Pattern.cpp ├── Out_of_boundary_paths.cpp ├── LICENSE ├── Wiggle_subsequence.cpp ├── Palindrome_Flipping.java ├── Simplify_Path.cpp ├── mergesort.cpp ├── CONTRIBUTING.md ├── README.md ├── CODE-OF-CONDUCT.md ├── Doctor Appointment system.cc └── main (1).cpp /C++/Sort 0 and 1.cpp: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /pascal triangle.cpp: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /C++/reverse_an_array.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/subhamtheone/HacktoberFest_2022/HEAD/C++/reverse_an_array.exe -------------------------------------------------------------------------------- /C++/vector-pair/pair_1.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/subhamtheone/HacktoberFest_2022/HEAD/C++/vector-pair/pair_1.exe -------------------------------------------------------------------------------- /C++/vector-pair/vector_1.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/subhamtheone/HacktoberFest_2022/HEAD/C++/vector-pair/vector_1.exe -------------------------------------------------------------------------------- /StudentReportManagementSystem/Faculty.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/subhamtheone/HacktoberFest_2022/HEAD/StudentReportManagementSystem/Faculty.txt -------------------------------------------------------------------------------- /StudentReportManagementSystem/Student.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/subhamtheone/HacktoberFest_2022/HEAD/StudentReportManagementSystem/Student.txt -------------------------------------------------------------------------------- /StudentReportManagementSystem/projectImages/2.homePage.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/subhamtheone/HacktoberFest_2022/HEAD/StudentReportManagementSystem/projectImages/2.homePage.png -------------------------------------------------------------------------------- /StudentReportManagementSystem/projectImages/1.IntroPage.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/subhamtheone/HacktoberFest_2022/HEAD/StudentReportManagementSystem/projectImages/1.IntroPage.png -------------------------------------------------------------------------------- /StudentReportManagementSystem/projectImages/23.ExitMenu.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/subhamtheone/HacktoberFest_2022/HEAD/StudentReportManagementSystem/projectImages/23.ExitMenu.png -------------------------------------------------------------------------------- /StudentReportManagementSystem/projectImages/4.adminMenu.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/subhamtheone/HacktoberFest_2022/HEAD/StudentReportManagementSystem/projectImages/4.adminMenu.png -------------------------------------------------------------------------------- /StudentReportManagementSystem/projectImages/13.FacultyMenu.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/subhamtheone/HacktoberFest_2022/HEAD/StudentReportManagementSystem/projectImages/13.FacultyMenu.png -------------------------------------------------------------------------------- /StudentReportManagementSystem/projectImages/18.StudentMenu.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/subhamtheone/HacktoberFest_2022/HEAD/StudentReportManagementSystem/projectImages/18.StudentMenu.png -------------------------------------------------------------------------------- /StudentReportManagementSystem/projectImages/3.LoginAsAdmin.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/subhamtheone/HacktoberFest_2022/HEAD/StudentReportManagementSystem/projectImages/3.LoginAsAdmin.png -------------------------------------------------------------------------------- /StudentReportManagementSystem/projectImages/5.addNewStudent.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/subhamtheone/HacktoberFest_2022/HEAD/StudentReportManagementSystem/projectImages/5.addNewStudent.png -------------------------------------------------------------------------------- /StudentReportManagementSystem/projectImages/8.addNewFaculty.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/subhamtheone/HacktoberFest_2022/HEAD/StudentReportManagementSystem/projectImages/8.addNewFaculty.png -------------------------------------------------------------------------------- /StudentReportManagementSystem/projectImages/12.loginAsFaculty.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/subhamtheone/HacktoberFest_2022/HEAD/StudentReportManagementSystem/projectImages/12.loginAsFaculty.png -------------------------------------------------------------------------------- /StudentReportManagementSystem/projectImages/17.LoginAsStudent.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/subhamtheone/HacktoberFest_2022/HEAD/StudentReportManagementSystem/projectImages/17.LoginAsStudent.png -------------------------------------------------------------------------------- /StudentReportManagementSystem/projectImages/11.DeleteExistingFaculty.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/subhamtheone/HacktoberFest_2022/HEAD/StudentReportManagementSystem/projectImages/11.DeleteExistingFaculty.png -------------------------------------------------------------------------------- /StudentReportManagementSystem/projectImages/16.UploadMarksOfStudent.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/subhamtheone/HacktoberFest_2022/HEAD/StudentReportManagementSystem/projectImages/16.UploadMarksOfStudent.png -------------------------------------------------------------------------------- /StudentReportManagementSystem/projectImages/6.viewExistingStudentDetails.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/subhamtheone/HacktoberFest_2022/HEAD/StudentReportManagementSystem/projectImages/6.viewExistingStudentDetails.png -------------------------------------------------------------------------------- /StudentReportManagementSystem/projectImages/7.ModifyExistingStudentDetails.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/subhamtheone/HacktoberFest_2022/HEAD/StudentReportManagementSystem/projectImages/7.ModifyExistingStudentDetails.png -------------------------------------------------------------------------------- /StudentReportManagementSystem/projectImages/9.viewExistingFacultyDetails.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/subhamtheone/HacktoberFest_2022/HEAD/StudentReportManagementSystem/projectImages/9.viewExistingFacultyDetails.png -------------------------------------------------------------------------------- /StudentReportManagementSystem/projectImages/10.ModifyExistingFacultyDetails.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/subhamtheone/HacktoberFest_2022/HEAD/StudentReportManagementSystem/projectImages/10.ModifyExistingFacultyDetails.png -------------------------------------------------------------------------------- /StudentReportManagementSystem/projectImages/14.ViewYourProfileFacultySection.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/subhamtheone/HacktoberFest_2022/HEAD/StudentReportManagementSystem/projectImages/14.ViewYourProfileFacultySection.png -------------------------------------------------------------------------------- /StudentReportManagementSystem/projectImages/19.viewYourProfileStudentSection.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/subhamtheone/HacktoberFest_2022/HEAD/StudentReportManagementSystem/projectImages/19.viewYourProfileStudentSection.png -------------------------------------------------------------------------------- /StudentReportManagementSystem/projectImages/21.ReviewAndPublishResultAdminSection.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/subhamtheone/HacktoberFest_2022/HEAD/StudentReportManagementSystem/projectImages/21.ReviewAndPublishResultAdminSection.png -------------------------------------------------------------------------------- /StudentReportManagementSystem/projectImages/15.viewExistingStudentRecordFacultySection.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/subhamtheone/HacktoberFest_2022/HEAD/StudentReportManagementSystem/projectImages/15.viewExistingStudentRecordFacultySection.png -------------------------------------------------------------------------------- /StudentReportManagementSystem/projectImages/22.ResultInStudentSectionAfterAdminPublished.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/subhamtheone/HacktoberFest_2022/HEAD/StudentReportManagementSystem/projectImages/22.ResultInStudentSectionAfterAdminPublished.png -------------------------------------------------------------------------------- /StudentReportManagementSystem/projectImages/20.ResultSectionWhenFinalResultNotUploadedByAdmin.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/subhamtheone/HacktoberFest_2022/HEAD/StudentReportManagementSystem/projectImages/20.ResultSectionWhenFinalResultNotUploadedByAdmin.png -------------------------------------------------------------------------------- /Armstong.py: -------------------------------------------------------------------------------- 1 | on=int(input("Enter No. - ")) 2 | temp=on 3 | dc=0 4 | while temp>0: 5 | digit=temp%10 6 | dc=dc+digit**3 7 | temp=temp//10 8 | if on==dc: 9 | print(on,"is an armstong number.") 10 | else: 11 | print(on,"is not an armstong number.") 12 | 13 | -------------------------------------------------------------------------------- /JavaScript/get_random_data.js: -------------------------------------------------------------------------------- 1 | import axios from 'axios' 2 | 3 | const BASE_URL = "https://jsonplaceholder.typicode.com/photos" 4 | 5 | function getRandomNumber() { 6 | return Math.floor(Math.random() * 5000); 7 | } 8 | fetch(`${BASE_URL}/${getRandomNumber()}`) 9 | .then(response => response.json()) 10 | .then(data => console.log(data)); -------------------------------------------------------------------------------- /If-else statment.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | int main() 3 | { 4 | int Aishwariya,Champa; 5 | printf("enter the value of Aishwariya"); 6 | scanf("%d",&Aishwariya); 7 | printf("enter the value of Champa"); 8 | scanf("%d",&Champa); 9 | if (Aishwariya>Champa) 10 | printf("Aishwariya is big"); 11 | else 12 | printf("Champa is big"); 13 | } 14 | -------------------------------------------------------------------------------- /opensource/pattern.java: -------------------------------------------------------------------------------- 1 | //Swarnam 2 | /* 3 | 1 4 | 1 2 5 | 1 2 3 6 | 1 2 3 4 7 | 1 2 3 4 5*/ 8 | public class pattern { 9 | 10 | public static void main(String[] args) { 11 | 12 | 13 | int n=5; 14 | for(int i=1; i<=n; i++) { 15 | for(int j=1; j<=i; j++) { 16 | System.out.print(j); 17 | } 18 | System.out.println(); 19 | } 20 | } 21 | 22 | } 23 | -------------------------------------------------------------------------------- /C++/Rotate Array.cpp: -------------------------------------------------------------------------------- 1 | // Problem Link : https://leetcode.com/problems/rotate-array/ 2 | 3 | class Solution { 4 | public: 5 | void rotate(vector& nums, int k) { 6 | int n = nums.size(); 7 | k = k % n; 8 | reverse(nums.begin() , nums.end()); 9 | reverse(nums.begin() , nums.begin() + k); 10 | reverse(nums.begin() + k , nums.end()); 11 | } 12 | }; -------------------------------------------------------------------------------- /C++/Climbing Stairs.cpp: -------------------------------------------------------------------------------- 1 | // Problem Link : https://leetcode.com/problems/climbing-stairs/ 2 | 3 | #include 4 | 5 | using namespace std; 6 | 7 | 8 | int main() { 9 | 10 | int n=3; 11 | vector dp(n+1,-1); 12 | 13 | dp[0]= 1; 14 | dp[1]= 1; 15 | 16 | for(int i=2; i<=n; i++){ 17 | dp[i] = dp[i-1]+ dp[i-2]; 18 | } 19 | cout< 4 | #include 5 | using namespace std; 6 | int main() 7 | { 8 | int ar[5]={4,5,1,2,3}; 9 | int minVal=INT_MAX,i; 10 | for(i=0;i<5;i++){ 11 | minVal=min(minVal,ar[i]); 12 | } 13 | cout<<"Minimum Value is "< 6 | using namespace std; 7 | int main() 8 | { 9 | int r; 10 | cout << "\nHow many row you will enter: "; 11 | cin >> r; 12 | for(int i=0; i 2 | using namespace std; 3 | 4 | bool linearSearch(int arr[], int n, int k) { 5 | for(int i=0; i> target; 16 | 17 | cout << (linearSearch(arr, 5, target) ? "Found" : "Not Found") << endl; 18 | } 19 | -------------------------------------------------------------------------------- /C++/Longest Increasing Subsequence.cpp: -------------------------------------------------------------------------------- 1 | // Problem Link : https://leetcode.com/problems/longest-increasing-subsequence/ 2 | 3 | int lengthOfLIS(vector& nums) 4 | { 5 | vector res; 6 | for(int i=0; i 5 | using namespace std; 6 | int main() 7 | { 8 | int n; 9 | cout << ("\nEnter the number of rows: "); 10 | cin >> n; 11 | for(int r=1; r<=n; r++) 12 | { 13 | for(int c=1; c<=n; c++) 14 | { 15 | cout << ("* "); 16 | } 17 | cout << endl; 18 | } 19 | } -------------------------------------------------------------------------------- /C++/Pattern printing/20LeftHalf_Inv_Pyramid.cpp: -------------------------------------------------------------------------------- 1 | // * * * * Left Half Inverted Pyramid. 2 | // * * * 3 | // * * 4 | // * 5 | #include 6 | using namespace std; 7 | int main() 8 | { 9 | int r; 10 | cout << "\nHow many row you want to print: "; 11 | cin >> r; 12 | for(int i=r; i>0; i--) 13 | { 14 | for(int j=i; j>0; j--) 15 | { 16 | cout << "* "; 17 | } 18 | cout << endl; 19 | } 20 | } -------------------------------------------------------------------------------- /C++/Pattern printing/13LeftHalfPyramidNumRev.cpp: -------------------------------------------------------------------------------- 1 | // 1 2 | // 2 1 3 | // 3 2 1 4 | // 4 3 2 1 5 | // 5 4 3 2 1 6 | #include 7 | using namespace std; 8 | int main() 9 | { 10 | int n; 11 | cout << ("\nEnter number of rows: "); 12 | cin >> n; 13 | for(int r=1; r<=n; r++) 14 | { 15 | for(int c=r; c>=1; c--) 16 | { 17 | cout << c << (" "); 18 | } 19 | cout << endl; 20 | } 21 | return 0; 22 | } -------------------------------------------------------------------------------- /C++/Pattern printing/3EqualNumberOfRows.cpp: -------------------------------------------------------------------------------- 1 | // 1 1 1 Square Matrix, Each Rows contain the same value. 2 | // 2 2 2 3 | // 3 3 3 4 | #include 5 | using namespace std; 6 | int main() 7 | { 8 | int n; 9 | cout << ("Enter number of rows: "); 10 | cin >> n; 11 | for(int r=1; r<=n; r++) 12 | { 13 | for(int c=1; c<=n; c++) 14 | { 15 | cout << r << (" "); 16 | } 17 | cout << endl; 18 | } 19 | return 0; 20 | } -------------------------------------------------------------------------------- /C++/Pattern printing/2EqualNumberOfCols.cpp: -------------------------------------------------------------------------------- 1 | // 1 2 3 Square matrix, Each Columns contain the same N value. 2 | // 1 2 3 3 | // 1 2 3 4 | #include 5 | using namespace std; 6 | int main() 7 | { 8 | int n; 9 | cout << ("\nEnter number of rows: "); 10 | cin >> n; 11 | for(int r=1; r<=n; r++) 12 | { 13 | for(int c=1; c<=n; c++) 14 | { 15 | cout << c << (" "); 16 | } 17 | cout << endl; 18 | } 19 | return 0; 20 | } -------------------------------------------------------------------------------- /C++/Pattern printing/5EqualCCharofRows.cpp: -------------------------------------------------------------------------------- 1 | // A A A Square Matrix, Rows contains the same n value. 2 | // B B B 3 | // C C C 4 | #include 5 | using namespace std; 6 | int main() 7 | { 8 | int n; 9 | cout << ("Enter number of rows: "); 10 | cin >> n; 11 | for(int r=1; r<=n; r++) 12 | { 13 | for(int c=1; c<=n; c++) 14 | { 15 | cout << ((char)(r+64)) << (" "); 16 | } 17 | cout << endl; 18 | } 19 | return 0; 20 | } -------------------------------------------------------------------------------- /opensource/palindrome.py: -------------------------------------------------------------------------------- 1 | #himanshulenka 2 | # This program performs palindrome check for a number 3 | 4 | 5 | Number = input("Enter the number to be verified :" ) 6 | val = int(Number) 7 | #checking for a palindrome in the given string 8 | if Number == str(Number)[::-1]: 9 | print('The given number is PALINDROME') 10 | else: 11 | print('The given number is NOT a PALINDROME') 12 | except ValueError: 13 | print("! ! ! A valid numeric input is not entered ! ! !") -------------------------------------------------------------------------------- /C++/JumpGame.cpp: -------------------------------------------------------------------------------- 1 | // https://leetcode.com/problems/jump-game/ 2 | // Difficulty : Medium Level 3 | // 170/170 test cases passed. 4 | // Success Rate = 38.4% 5 | 6 | class Solution { 7 | public: 8 | bool canJump(vector& nums) { 9 | int n = nums.size(); 10 | int max_reach = 0; 11 | for (int i = 0; i < n; i{ 12 | if (i > max_reach) return false; 13 | max_reach = max(max_reach, i + nums[i]); 14 | } 15 | return true; 16 | } 17 | }; -------------------------------------------------------------------------------- /C++/Pattern printing/14LeftHalfPyramidNumInc.cpp: -------------------------------------------------------------------------------- 1 | // 1 2 | // 2 3 3 | // 4 5 6 4 | // 7 8 9 10 5 | // 11 12 13 14 15 6 | #include 7 | using namespace std; 8 | int main() 9 | { 10 | int n, x=1; 11 | cout << "\nEnter number of rows: "; 12 | cin >> n; 13 | for(int r=1; r<=n; r++) 14 | { 15 | for(int c=1; c<=r; c++) 16 | { 17 | cout << x << " "; 18 | x++; 19 | } 20 | cout << endl; 21 | } 22 | return 0; 23 | } 24 | -------------------------------------------------------------------------------- /C++/Pattern printing/4EqualCharofRows.cpp: -------------------------------------------------------------------------------- 1 | // a a a Square Matrix, Rows contain the same N value. 2 | // b b b 3 | // c c c 4 | #include 5 | using namespace std; 6 | int main() 7 | { 8 | int n; 9 | cout << ("\nEnter number of rows in Alphabet form: "); 10 | cin >> n; 11 | for(int r=1; r<=n; r++) 12 | { 13 | for(int c=1; c<=n; c++) 14 | { 15 | cout << ((char)(r+96)); 16 | } 17 | cout << endl; 18 | } 19 | return 0; 20 | } -------------------------------------------------------------------------------- /Mounted array.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | int peakvalue(int arr[],int n){ 4 | int s=0,e=n-1; 5 | int mid=s+(e-s)/2; 6 | while (s 2 | #include 3 | #include 4 | using namespace std; 5 | int main() 6 | { 7 | int n,l,i,j,temp; 8 | double d,max,s; 9 | cin>>n>>l; 10 | int a[n]; 11 | for(i=0;i>a[i]; 13 | sort(a,a+n); 14 | max=a[0]; 15 | for(i=0;i=max) 19 | max=s/2; 20 | } 21 | if(max<(l-a[n-1])) 22 | d=l-a[n-1]; 23 | else 24 | d=max; 25 | cout< 6 | using namespace std; 7 | int main() 8 | { 9 | int n; 10 | cout << ("\nEnter number of rows: "); 11 | cin >> n; 12 | for(int r=1; r<=n; r++) 13 | { 14 | for(int c=1; c<=n; c++) 15 | { 16 | cout << ((char)(96+c)) << (" "); 17 | } 18 | cout << endl; 19 | } 20 | return 0; 21 | } -------------------------------------------------------------------------------- /C++/Pattern printing/6EqualCCharOfCols.cpp: -------------------------------------------------------------------------------- 1 | // A B C D Square matrix, Each Columns contain the same N value. 2 | // A B C D 3 | // A B C D 4 | // A B C D 5 | #include 6 | using namespace std; 7 | int main() 8 | { 9 | int n; 10 | cout << ("\nEnter number of rows: "); 11 | cin >> n; 12 | for(int r=1; r<=n; r++) 13 | { 14 | for(int c=1; c<=n; c++) 15 | { 16 | cout << ((char)(c + 64)) << (" "); 17 | } 18 | cout << endl; 19 | } 20 | return 0; 21 | } -------------------------------------------------------------------------------- /C++/Pattern printing/25Full_Pyramid_Inverted.cpp: -------------------------------------------------------------------------------- 1 | // * * * * 2 | // * * * 3 | // * * 4 | // * 5 | #include 6 | using namespace std; 7 | int main() 8 | { 9 | int r; 10 | cout << "\nHow many row you want to print: "; 11 | cin >> r; 12 | for(int i=r; i>0; i--) 13 | { 14 | for(int spc=r; spc>i; spc--) 15 | { 16 | cout << " "; 17 | } 18 | for(int j=i; j>0; j--) 19 | { 20 | cout << "* "; 21 | } 22 | cout << endl; 23 | } 24 | } -------------------------------------------------------------------------------- /C++/Pattern printing/19Full_Pyramid.cpp: -------------------------------------------------------------------------------- 1 | // * 2 | // * * 3 | // * * * 4 | // * * * * 5 | #include 6 | using namespace std; 7 | int main() 8 | { 9 | int n; 10 | cout << "\nEnter number of rows: "; 11 | cin >> n; 12 | for(int r=1; r<=n; r++) 13 | { 14 | for(int c=n; c>=1; c--) 15 | { 16 | if(c<=r) 17 | cout << "* "; 18 | else 19 | cout << " "; 20 | } 21 | cout << endl; 22 | } 23 | return 0; 24 | } -------------------------------------------------------------------------------- /C++/Pattern printing/21MinusMultiplySign.cpp: -------------------------------------------------------------------------------- 1 | // - - - - * 2 | // - - - * * 3 | // - - * * * 4 | // - * * * * 5 | // * * * * * 6 | #include 7 | using namespace std; 8 | int main() 9 | { 10 | int n; 11 | cout << "\nEnter number of rows: "; 12 | cin >> n; 13 | for(int r=1; r<=n; r++) 14 | { 15 | for(int c=1; c<=n; c++) 16 | { 17 | if(c > n-r) 18 | cout << "* "; 19 | else 20 | cout << "- "; 21 | } 22 | cout << endl; 23 | } 24 | return 0; 25 | } -------------------------------------------------------------------------------- /C++/Pattern printing/9Pattern.cpp: -------------------------------------------------------------------------------- 1 | // 1 1 1 1 1 2 | // 1 1 1 2 2 3 | // 1 1 3 3 3 4 | // 1 4 4 4 4 5 | // 5 5 5 5 5 6 | #include 7 | using namespace std; 8 | int main() 9 | { 10 | int n; 11 | cout << ("\nEnter number of rows: "); 12 | cin >> n; 13 | for(int r=1; r<=n; r++) 14 | { 15 | for(int c=1; c<=n; c++) 16 | { 17 | if(c>(n-r)) 18 | cout << r << (" "); 19 | else 20 | cout << ("1 "); 21 | } 22 | cout << endl; 23 | } 24 | return 0; 25 | } -------------------------------------------------------------------------------- /C++/Reverse Pairs.cpp: -------------------------------------------------------------------------------- 1 | // Problem Link : https://leetcode.com/problems/reverse-pairs/ 2 | 3 | #include 4 | using namespace std; 5 | int reversePairs(vector < int > & arr) { 6 | int Pairs = 0; 7 | for (int i = 0; i < arr.size(); i++) { 8 | for (int j = i + 1; j < arr.size(); j++) { 9 | if (arr[i] > 2 * arr[j]) Pairs++; 10 | } 11 | } 12 | return Pairs; 13 | } 14 | 15 | 16 | int main() 17 | { 18 | vector arr{1,3,2,3,1}; 19 | cout<<"The Total Reverse Pairs are "< 6 | using namespace std; 7 | int main() 8 | { 9 | int r; 10 | cout << "\nHow many row you will enter in a row: "; 11 | cin >> r; 12 | for(int i=r; i>0; i--) 13 | { 14 | for(int j=r; j>i; j--) 15 | { 16 | cout << " "; 17 | } 18 | for(int k=0; k=0;i-- ) { 8 | char ch= s.charAt(i); 9 | t=t+ch; 10 | } 11 | if(s.equals(t)) { 12 | return true; 13 | } 14 | else { 15 | return false; 16 | } 17 | } 18 | public static void main(String[] args) { 19 | Scanner ms= new Scanner(System.in); 20 | String str= ms.next(); 21 | boolean p= checkP(str); 22 | System.out.println(p); 23 | ms.close(); 24 | } 25 | } -------------------------------------------------------------------------------- /C++/Count digit & Sum of Digit.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() { 4 | int n; 5 | int sum=0; 6 | int count = 0; 7 | printf("Enter a Number : "); 8 | scanf("%d", &n); 9 | // For sum 10 | int x=n; 11 | while (x != 0) { 12 | sum = sum + x % 10; 13 | x = x / 10; 14 | } 15 | //For count digit 16 | while (n!=0) 17 | { 18 | n /= 10; 19 | ++count; 20 | } 21 | 22 | 23 | 24 | printf(" Number of digits: %d \n", count); 25 | printf(" Sum of digits : %d ",sum); 26 | } 27 | -------------------------------------------------------------------------------- /C++/Next Permutation.cpp: -------------------------------------------------------------------------------- 1 | // Problem Link: https://leetcode.com/problems/next-permutation/ 2 | 3 | 4 | 5 | class Solution { 6 | public: 7 | void nextPermutation(vector &num) 8 | { 9 | if (num.empty()) return; 10 | 11 | 12 | int i; 13 | for (i = num.size()-2; i >= 0; --i) 14 | { 15 | if (num[i] < num[i+1]) break; 16 | } 17 | reverse(begin(num)+i+1, end(num)); 18 | if (i == -1) return; 19 | auto itr = upper_bound(begin(num)+i+1, end(num), num[i]); 20 | swap(num[i], *itr); 21 | } 22 | }; -------------------------------------------------------------------------------- /JavaScript/README.md: -------------------------------------------------------------------------------- 1 | # Running the code locally 2 | ### Method 1: 3 | You can directly copy the code from the snippets and run 4 | it in your browser's console. 5 | 6 | **Exception**: Code using fetch API can't be directly run on console 7 | Follow other methods mentioned below. 8 | 9 | ### Method 2: 10 | Prerequisites: 11 | - Node.js 12 | - Text Editor (VS Code, Atom, Sublime, etc.) 13 | 14 | If using VS Code, Install Code Runner from extensions and then open the js file and then select 'Run code'(Play button on top right) 15 | 16 | else, just run ```node file_name.js``` 17 | 18 | Reference: 19 | https://stackoverflow.com/a/38768079 -------------------------------------------------------------------------------- /C++/Pattern printing/8UppLowCharOfRows.cpp: -------------------------------------------------------------------------------- 1 | // a a a a Square Matrix, 2 | // B B B B Upper & Lower casee characters but in alternate rows. 3 | // c c c c 4 | // D D D D 5 | #include 6 | using namespace std; 7 | int main() 8 | { 9 | int n; 10 | cout << ("\nEnter number of rows: "); 11 | cin >> n; 12 | for(int r=1; r<=n; r++) 13 | { 14 | for(int c=1; c<=n; c++) 15 | { 16 | if(0 == r % 2) 17 | cout << ((char)(64+r)) << (" "); 18 | else 19 | cout << ((char)(96+r)) << (" "); 20 | } 21 | cout << endl; 22 | } 23 | return 0; 24 | } -------------------------------------------------------------------------------- /opensource/leapyear.py: -------------------------------------------------------------------------------- 1 | #himanshukumarlenka 2 | #leap year in python prg: 3 | 4 | #function defined 5 | def LeapYearCheck(input_year): 6 | if (input_year % 4) == 0: 7 | if (input_year % 100) == 0: 8 | if (input_year % 400) == 0: 9 | return True 10 | else: 11 | return False 12 | else: 13 | return True 14 | else: 15 | return False 16 | 17 | 18 | # Driver Code 19 | input_year = int(input("Enter the Year to be checked: ")) 20 | if(LeapYearCheck(input_year)): 21 | print("Leap Year") 22 | else: 23 | print("Not a Leap Year") -------------------------------------------------------------------------------- /C++/countSort.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | void countSort(int arr[], int n){ 5 | map mp; 6 | for(int i=0;i>n; 22 | int arr[n]; 23 | cout<<"Enter the array: "; 24 | for(int i=0;i>arr[i]; 26 | } 27 | countSort(arr,n); 28 | cout<<"Sorted Array: "; 29 | for(int i=0;i& nums) { 2 | 3 | // To point to the zero 4 | int zeroindex = 0; 5 | 6 | for(int i=0 ; i< nums.size() ; i++) 7 | { 8 | // if number is not zero then swap it with index having number zero and increment zero index 9 | if(nums[i] != 0) 10 | { 11 | swap(nums[i] , nums[zeroindex]); 12 | zeroindex++; 13 | } 14 | } 15 | 16 | // at end all zeros will be swapped to end 17 | // try to run 2 test cases for better understanding 18 | 19 | } 20 | -------------------------------------------------------------------------------- /C++/Pattern printing/26Left-RightHalfPyramid.cpp: -------------------------------------------------------------------------------- 1 | // * * Right-Left half Pyramd. 2 | // * * * * 3 | // * * * * * * 4 | // * * * * * * * * kacchi basti - barkat colony - right hand - got-it. 5 | #include 6 | using namespace std; 7 | int main() 8 | { 9 | int n; 10 | cout << ("\nHow many row you want to print: "); 11 | cin >> n; 12 | for(int r=1; r<=n; r++) 13 | { 14 | for(int c=1; c<=2*n; c++) 15 | { 16 | if(c<=r || c>(2*n-r)) 17 | cout << ("* "); 18 | else 19 | cout << (" "); 20 | } 21 | cout << endl; 22 | } 23 | return 0; 24 | } -------------------------------------------------------------------------------- /C++/Single_Operation_Part_1.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int main() 5 | { 6 | int l, T , y ; 7 | string s; 8 | cin >> T; 9 | 10 | for (int k = 1; k <= T; k++) 11 | { 12 | 13 | cin >> l; 14 | 15 | cin >> s; 16 | 17 | y = 0; 18 | 19 | 20 | for (int j = 0; j < l; j++) 21 | { 22 | if (s[j] == '1') 23 | { 24 | y++; 25 | 26 | } 27 | else 28 | { 29 | break; 30 | } 31 | } 32 | cout << y << endl; 33 | 34 | 35 | } 36 | return 0; 37 | } -------------------------------------------------------------------------------- /opensource/fibo.java: -------------------------------------------------------------------------------- 1 | 2 | import java.util.*; 3 | public class fibo { 4 | 5 | public static void main(String[] args) { 6 | 7 | Scanner ms=new Scanner(System.in); 8 | int n=ms.nextInt(); 9 | ms.close(); 10 | int a=0; 11 | int b=1; 12 | 13 | if(n<=0) { 14 | System.out.println("Invalid Input"); 15 | } 16 | else if(n==1) { 17 | System.out.print(a+" "); 18 | } 19 | else if(n==2) { 20 | System.out.println(a+" "+ b+" "); 21 | } 22 | else { 23 | System.out.print(a+" "+ b+" "); 24 | for(int i=3; i<=n;i++) { 25 | int c=a+b; 26 | System.out.print(c+ " "); 27 | a=b; 28 | b=c; 29 | 30 | 31 | } 32 | 33 | } 34 | 35 | 36 | } 37 | 38 | } 39 | 40 | 41 | -------------------------------------------------------------------------------- /C++/ValidParenthesis.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | bool isValid(string s) { 4 | stack st; 5 | for(int i=0;i 2 | using namespace std; 3 | 4 | int maxSubArraySum(int a[], int size) 5 | { 6 | int max_so_far = INT_MIN, max_ending_here = 0; 7 | 8 | for (int i = 0; i < size; i++) { 9 | max_ending_here = max_ending_here + a[i]; 10 | if (max_so_far < max_ending_here) 11 | max_so_far = max_ending_here; 12 | 13 | if (max_ending_here < 0) 14 | max_ending_here = 0; 15 | } 16 | return max_so_far; 17 | } 18 | int main() 19 | { 20 | int a[] = { -2, -3, 4, -1, -2, 1, 5, -3 }; 21 | int n = sizeof(a) / sizeof(a[0]); 22 | int max_sum = maxSubArraySum(a, n); 23 | cout << "Maximum contiguous sum is " << max_sum< 2 | #include 3 | #include 4 | using namespace std; 5 | int bottom_up_rod_cutting(int price[],int n) 6 | { 7 | int value[n+1]; 8 | value[0]=0; 9 | for(int j=1;j<=n;j++) 10 | { 11 | int max_value=-1000; 12 | for(int i=1;i<=j;i++) 13 | { 14 | max_value=max(max_value,price[i]+value[j-i]); 15 | } 16 | value[j]=max_value; 17 | } 18 | return value[n]; 19 | } 20 | int main() 21 | { 22 | int p_arr[]={0,1,5,8,9,10,17,17,20,24,30,12}; 23 | int n=sizeof(p_arr)/sizeof(p_arr[0]); 24 | cout << "Maximum revenue = "< 7 | using namespace std; 8 | int main() 9 | { 10 | int n, x=1; 11 | cout << "\nEnter number of rows: "; 12 | cin >> n; 13 | for(int r=1; r<=n; r++) 14 | { 15 | for(int c=1; c<=r; c++) 16 | { 17 | if(0 == r % 2) 18 | { 19 | cout << x << " "; 20 | if(c == r) 21 | x++; 22 | } 23 | else 24 | cout << ((char)(64+x)) << " "; 25 | } 26 | cout << endl; 27 | } 28 | return 0; 29 | } -------------------------------------------------------------------------------- /BubbleSort.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | int main () 4 | { 5 | int i, j,temp,pass=0; 6 | int a[10] = {10,2,0,14,43,25,18,1,5,45}; 7 | cout <<"Input list ...\n"; 8 | for(i = 0; i<10; i++) { 9 | cout < 7 | using namespace std; 8 | int main() 9 | { 10 | int n, x=1; 11 | cout << ("\nEnter number of rows: "); 12 | cin >> n; 13 | for(int r=1; r<=n; r++) 14 | { 15 | for(int c=1; c<=n; c++) 16 | { 17 | if(r == 1 || r == n|| c == 1 || c == n) 18 | { 19 | cout << ("* "); 20 | } 21 | else 22 | { 23 | cout << ((char)(64+x)) << (" "); 24 | x++; 25 | } 26 | } 27 | cout << endl; 28 | } 29 | return 0; 30 | } -------------------------------------------------------------------------------- /C++/towerofhanoi.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Name : Rounak Ghosh 3 | Username : Rounak-Ghosh 4 | About : 4th year undergrad student at GCETTB 5 | */ 6 | 7 | #include 8 | using namespace std; 9 | 10 | void tower(int n, char source, char helper, char destination) 11 | { 12 | if(n==1) 13 | { 14 | cout << "Move from " << source << " to " << destination << endl; 15 | return; 16 | } 17 | tower(n-1, source, destination, helper); 18 | cout << "Move from " << source << " to " << destination << endl; 19 | tower(n-1, helper, source, destination); 20 | } 21 | 22 | int main() 23 | { 24 | int n; 25 | cin >> n; 26 | tower(n, 'A', 'B', 'C'); 27 | return 0; 28 | } -------------------------------------------------------------------------------- /C++/Trapping Rain Water.cpp: -------------------------------------------------------------------------------- 1 | // Problem Link: https://leetcode.com/problems/trapping-rain-water/ 2 | 3 | 4 | class Solution { 5 | public: 6 | int trap(vector& A) { 7 | int N = A.size(), ans = 0; 8 | 9 | vector left(N, 0), right(N, 0); 10 | 11 | for(int i = 1; i < N; i++) { 12 | left[i] = max(left[i - 1], A[i - 1]); 13 | } 14 | 15 | for(int i = N - 2; i >= 0; i--) { 16 | right[i] = max(right[i + 1], A[i + 1]); 17 | } 18 | 19 | for(int i = 1; i < N - 1; i++) { 20 | ans += max(0, min(left[i], right[i]) - A[i]); 21 | } 22 | 23 | return ans; 24 | 25 | } 26 | }; -------------------------------------------------------------------------------- /JavaScript/use_localstorage.js: -------------------------------------------------------------------------------- 1 | /* The Web Storage API enables us to preserve data in the browser. 2 | The localStorage interface can store up to 5MB per domain (in most browsers) 3 | as opposed to the 4KB limit cookies can store. 4 | 5 | you can check it out under Application->Storage->Local Storage in developer tools 6 | in Google Chrome. 7 | */ 8 | 9 | // Store a new item in local storage 10 | localStorage.setItem('username', 'Pritam'); 11 | 12 | // Get an item 13 | console.log(localStorage.getItem('username')); 14 | 15 | // Check if an item exists 16 | if (localStorage.getItem('username')) { 17 | console.log('Item exists!'); 18 | } 19 | 20 | //Remove an item from storage 21 | localStorage.removeItem('username'); 22 | -------------------------------------------------------------------------------- /C++/Rod_cutting.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #define MAX(x,y) (((x)>(y))?(x):(y)) 5 | const int INF=100000; 6 | int bottom_up_rod_cutting(int a[],int n) 7 | { 8 | int r[n+1]; 9 | r[0]=0; 10 | int i,j; 11 | for(i=1;i<=n;i++) 12 | { 13 | int maximum_revenue=-1*INF; 14 | for(j=1;j<=i;j++) 15 | { 16 | maximum_revenue=MAX(maximum_revenue,a[j]+r[i-j]); 17 | } 18 | r[i]=maximum_revenue; 19 | } 20 | return r[n]; 21 | } 22 | int main() 23 | { 24 | int a[]={0,1,5,8,9,10,17,17,20,24,30,12}; 25 | int n=sizeof(a)/sizeof(a[0]); 26 | printf("%d\n",bottom_up_rod_cutting(a,n)); 27 | getch(); 28 | return 0; 29 | } 30 | -------------------------------------------------------------------------------- /opensource/rankthepermutation.py: -------------------------------------------------------------------------------- 1 | #Rank the permutation in python lang: 2 | #himanshukumarlenka 3 | 4 | class Solution: 5 | def findRank(self, S): 6 | N = len(S) 7 | def getfact(n): 8 | if n == 0 or n == 1: 9 | return 1 10 | return n * getfact(n-1) 11 | 12 | 13 | ans = 0 14 | for i in range(N): 15 | val1 = ord(S[i]) 16 | count = 0 17 | factval = 1 18 | for j in range(i+1,N): 19 | val2 = ord(S[j]) 20 | if val2 < val1: 21 | count += 1 22 | 23 | factval = getfact(N-1-i) 24 | ans += ( count * factval ) 25 | 26 | 27 | return (ans + 1) -------------------------------------------------------------------------------- /C++/Pattern printing/16AsteriskDollarlogo.cpp: -------------------------------------------------------------------------------- 1 | // * Asterisk with Dollar Sign pattern. 2 | // $ * 3 | // * $ * 4 | // $ * $ * 5 | // * $ * $ * 6 | #include 7 | using namespace std; 8 | int main() 9 | { 10 | int n; 11 | cout << "\nEnter number of rows: "; 12 | cin >> n; 13 | for(int r=1; r<=n; r++) 14 | { 15 | int flag=1; 16 | for(int c=1; c<=r; c++) 17 | { 18 | if((0 == r % 2 && c == 1) || flag == 0) 19 | { 20 | cout << "$ "; 21 | flag = 1; 22 | } 23 | else 24 | { 25 | cout << "* "; 26 | flag = 0; 27 | } 28 | } 29 | cout << endl; 30 | } 31 | return 0; 32 | } -------------------------------------------------------------------------------- /C++/Pattern printing/15Left_RightNumbers.cpp: -------------------------------------------------------------------------------- 1 | // 1 2 | // 3 2 3 | // 4 5 6 4 | // 10 9 8 7 5 | #include 6 | using namespace std; 7 | int main() 8 | { 9 | int n, x=1, flag=1; 10 | cout << "\nEnter number of rows: "; 11 | cin >> n; 12 | for(int r=1, y=0; r<=n; r++) 13 | { 14 | int a = y + 1; 15 | y = y + r; 16 | int z = y; 17 | for(int c=1; c<=r; c++) 18 | { 19 | if(0 == flag % 2 || r==1) 20 | { 21 | cout << z << " "; 22 | z--; 23 | } 24 | else 25 | { 26 | cout << a << " "; 27 | a++; 28 | } 29 | } 30 | flag++; 31 | cout << endl; 32 | } 33 | return 0; 34 | } -------------------------------------------------------------------------------- /opensource/sh.java: -------------------------------------------------------------------------------- 1 | //Swarnam 2 | //Finding Second Highest Elements in Array 3 | import java.util.*; 4 | public class sh { 5 | 6 | 7 | 8 | public static void main(String[] args) { 9 | Scanner ms= new Scanner(System.in); 10 | int n= ms.nextInt(); 11 | int arr[] = new int [n]; 12 | for(int i=0;ihigh) { 21 | sh=high; 22 | high=arr[i]; 23 | } 24 | if(arr[i]sh) { 25 | sh=arr[i]; 26 | } 27 | } 28 | System.out.println("Second highest is "+ sh); 29 | ms.close(); 30 | 31 | 32 | 33 | 34 | } 35 | 36 | } 37 | -------------------------------------------------------------------------------- /C++/insertion sort implementation: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | void insertionSort(int arr[], int n) 4 | { 5 | int i, key, j; 6 | for (i = 1; i < n; i++) 7 | { 8 | key = arr[i]; 9 | j = i - 1; 10 | while (j >= 0 && arr[j] > key) 11 | { 12 | arr[j + 1] = arr[j]; 13 | j = j - 1; 14 | } 15 | arr[j + 1] = key; 16 | } 17 | } 18 | void printArray(int arr[], int n) 19 | { 20 | int i; 21 | for (i = 0; i < n; i++) 22 | cout << arr[i] << " "; 23 | cout << endl; 24 | } 25 | int main() 26 | { 27 | int arr[] = { 12, 11, 13, 5, 6 }; 28 | int N = sizeof(arr) / sizeof(arr[0]); 29 | 30 | insertionSort(arr, N); 31 | printArray(arr, N); 32 | 33 | return 0; 34 | } 35 | -------------------------------------------------------------------------------- /C++/Dungeon_Game.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | int calculateMinimumHP(vector>& dungeon) { 4 | int m=dungeon.size(), n=dungeon[0].size(); 5 | vector> dp(m, vector(n, 11111111)); 6 | for(int i=m-1; i>=0; i--) { 7 | for(int j=n-1; j>=0; j--) { 8 | if(i==m-1 && j==n-1) 9 | dp[i][j] = max(1, 1 - dungeon[i][j]); 10 | else if(i==m-1) 11 | dp[i][j] = max(1, dp[i][j+1] - dungeon[i][j]); 12 | else if(j==n-1) 13 | dp[i][j] = max(1, dp[i+1][j] - dungeon[i][j]); 14 | else 15 | dp[i][j] = max(1, min(dp[i+1][j], dp[i][j+1]) - dungeon[i][j]); 16 | } 17 | } 18 | 19 | return dp[0][0]; 20 | } 21 | }; 22 | -------------------------------------------------------------------------------- /C++/Pattern printing/29_90D_RotateFullPyd.cpp: -------------------------------------------------------------------------------- 1 | // * 2 | // * * 3 | // * * * 4 | // * * 5 | // * 6 | #include 7 | using namespace std; 8 | int main() 9 | { 10 | int n,a, flag=1; 11 | cout << "\nEnter number of columns: "; 12 | cin >> n; 13 | for(int r=1; r<=2*n-1; r++) 14 | { 15 | for(int c=1; c<=n; c++) 16 | { 17 | if(c<=r && c<=n && flag==1) { 18 | cout << "* "; 19 | if(c==n) { 20 | a = n; 21 | flag=0; 22 | } 23 | } 24 | else if(r>n && c<=a) { 25 | cout << "* "; 26 | } 27 | else 28 | cout << " "; 29 | } 30 | a--; 31 | cout << endl; 32 | } 33 | } -------------------------------------------------------------------------------- /C++/Pattern printing/24FullPyramid_Num.cpp: -------------------------------------------------------------------------------- 1 | // 1 1*1 = 1 - 1 = 0 r==1 2 | // 121 2*2 = 4 - 1 = 3 3 | // 12321 3*3 = 6 - 1 = 5 4 | // 1234321 4*4 = 8 - 1 = 7 5 | // 123454321 6 | #include 7 | using namespace std; 8 | int main() 9 | { 10 | int n, a; 11 | cout << "\nEnter number of rows: "; 12 | cin >> n; 13 | for(int r=1; r<=n; r++) 14 | { 15 | for(int c=1; c<=n-r; c++) 16 | cout << " "; 17 | for(int k=1; k<=2*r-1; k++) 18 | { 19 | if(k> dp(n + 1, vector(m + 1, 0)); 11 | for (int i = 0; i <= n; i++) { 12 | dp[i][0] = 1; 13 | } 14 | for (int i = 1; i <= n; i++) { 15 | for (int j = 1; j <= m; j++) { 16 | if (s[i - 1] == t[j - 1]) { 17 | dp[i][j] = dp[i - 1][j - 1] + dp[i - 1][j]; 18 | } 19 | else { 20 | dp[i][j] = dp[i - 1][j]; 21 | } 22 | } 23 | } 24 | return dp[n][m]; 25 | } 26 | }; -------------------------------------------------------------------------------- /C++/length_longest_common_sequence.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #define ll long long int 3 | using namespace std; 4 | int main() 5 | { 6 | ll t; 7 | cin>>t; 8 | while(t--){ 9 | ll n,m,k,count=0; 10 | cin>>n>>m>>k; 11 | ll a[n]; 12 | for(ll i=0;i>a[i]; 14 | if(a[i]!=k){ 15 | count++; 16 | } 17 | } 18 | int i,j; 19 | bool f=1; 20 | for(i=0;i n) 23 | System.out.println(n + " is an abundant number"); 24 | else 25 | System.out.println(n + " is not an abundant number"); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /C++/CountNumberOfText.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | int mod=1e9+7; 4 | int func(string &s,int i,int n,vector &dp){ 5 | if(i>=n)return 1; 6 | if(dp[i]!=-1)return dp[i]; 7 | int ans=0; 8 | if(i+1 dp(n+1,-1); 25 | return func(s,0,n,dp); 26 | } 27 | }; 28 | -------------------------------------------------------------------------------- /JavaScript/connectingNodeWithMongoDB.js: -------------------------------------------------------------------------------- 1 | var db = null // global variable to hold the connection 2 | 3 | MongoClient.connect('mongodb://localhost:27017/', function(err, client) { 4 | if(err) { console.error(err) } 5 | db = client.db('test') // once connected, assign the connection to the global variable 6 | }) 7 | 8 | app.get('/', function(req, res) { 9 | db.collection('test').find({}).toArray(function(err, docs) { 10 | if(err) { console.error(err) } 11 | res.send(JSON.stringify(docs)) 12 | }) 13 | }) 14 | 15 | 16 | var conn = MongoClient.connect('mongodb://localhost:27017/') // returns a Promise 17 | 18 | app.get('/', function(req, res) { 19 | conn.then(client=> client.db('test').collection('test').find({}).toArray(function(err, docs) { 20 | if(err) { console.error(err) } 21 | res.send(JSON.stringify(docs)) 22 | })) 23 | }) 24 | 25 | 26 | -------------------------------------------------------------------------------- /JavaScript/date_manipulation.js: -------------------------------------------------------------------------------- 1 | //creating a new date 2 | let date = new Date() // Ex. Output: Sun Oct 23 2022 00:48:49 GMT+0530 (India Standard Time) 3 | console.log(date) 4 | 5 | let current_year = date.getFullYear(); // O/P: 2022 6 | console.log(current_year) 7 | 8 | let newDate = new Date(1223727718982) // Passing a timestamp 9 | // Sat Oct 11 2008 14:21:58 GMT+0200 (Central European Summer Time) 10 | 11 | newDate = new Date("2022-23-10T14:56:23") 12 | 13 | //format according to the computer's default locale 14 | // Intl.DateTimeFormat().format(newDate) 15 | // "23/10/2022" 16 | 17 | /* **CUSTOM Date Formats** */ 18 | newDate.getMonth() // 0 (zero-based index) 19 | newDate.getDate() // 9 20 | newDate.getDay() // 6 (zero-based index starting from Sunday) 21 | newDate.getHours() // 14 22 | newDate.getMinutes() // 56 23 | newDate.getUTCHours() // 9 24 | newDate.getUTCDate() // 9 -------------------------------------------------------------------------------- /remove_Duplicates_from_Sorted_Array.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | class Solution { 5 | public: 6 | int removeDuplicates(vector& nums) { 7 | int insertIndex = 1; 8 | for(int i = 1; i < nums.size(); i++){ 9 | // We skip to next index if we see a duplicate element 10 | if(nums[i - 1] != nums[i]) { 11 | // Storing the unique element at insertIndex index and incrementing the insertIndex by 1 12 | nums[insertIndex] = nums[i]; 13 | insertIndex++; 14 | } 15 | } 16 | return insertIndex; 17 | } 18 | }; 19 | void main(){ 20 | Solution s; 21 | vector nums = {1,1,2,2,3,3,4,4,5,5,6,6,7,7,8,8,9,9,10,10}; 22 | int len = s.removeDuplicates(nums); 23 | for(int i = 0; i < len; i++){ 24 | cout< 2 | using namespace std; 3 | const int N = 1e3+1; 4 | int wt[N]; 5 | int val[N]; 6 | int ans; 7 | int n,wt1; 8 | 9 | int knapsack(int n , int wt1 , int t[][1001]) 10 | { 11 | if(n==0 || wt1==0) return 0; 12 | 13 | 14 | if(t[n][wt1]!=-1) return t[n][wt1]; 15 | if(wt[n-1]<=wt1) 16 | { 17 | t[n][wt1] = max(val[n-1]+knapsack(n-1,wt1-wt[n-1],t),knapsack(n-1,wt1,t)); 18 | } 19 | else{ 20 | t[n][wt1] = knapsack(n-1,wt1,t); 21 | } 22 | return t[n][wt1]; 23 | } 24 | int main() 25 | { 26 | // int n; 27 | cin>>n; 28 | for(int i=0 ; i>wt[i]; 29 | for(int i=0 ; i>val[i]; 30 | // int wt1; 31 | cin>>wt1; 32 | // init(n,wt1); 33 | int t[1001][1001]; 34 | memset(t,-1,sizeof(t)); 35 | cout<> res; 3 | public: 4 | bool isPalin(const string s){ 5 | int lo=0, hi=s.size()-1; 6 | while(lo < hi){ 7 | if(s[lo++] != s[hi--]) return false; 8 | } 9 | return true; 10 | } 11 | void helper(int inx, const string s, vector &temp){ 12 | if(inx == s.size()){ 13 | res.push_back(temp); 14 | return; 15 | } 16 | for(int i=inx; i> partition(string s) { 25 | vector temp; 26 | helper(0, s, temp); 27 | return res; 28 | } 29 | }; 30 | -------------------------------------------------------------------------------- /Numbers/NivenNumbers.java: -------------------------------------------------------------------------------- 1 | //Name- Suman Meher 2 | //Username- sumanmeher 3 | 4 | //NIVEN NUMBER: An integer that is divisible by the sum of its digits when written in that base. 5 | //Ex: 12 etc. 6 | 7 | import java.util.Scanner; 8 | 9 | public class NivenNumbers { 10 | public static void main(String[] args) { 11 | int n, num, r, 12 | sum = 0; 13 | Scanner sc = new Scanner(System.in); 14 | System.out.println("Enter number: "); 15 | n = sc.nextInt(); 16 | num = n; 17 | while (num > 0) 18 | { 19 | r = num % 10; 20 | sum = sum + r; 21 | num = num / 10; 22 | } 23 | if (n % sum == 0) 24 | { 25 | System.out.println("A Niven Number"); 26 | } 27 | else 28 | { 29 | System.out.println("Not A Niven Number"); 30 | } 31 | sc.close(); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /H_Pattern.cpp: -------------------------------------------------------------------------------- 1 | // Author : pk 2 | // H pattern 3 | /* 4 | # # 5 | ## ## 6 | ### ### 7 | #### #### 8 | ##### ##### 9 | ############ 10 | ############ 11 | ##### ##### 12 | #### #### 13 | ### ### 14 | ## ## 15 | # # 16 | */ 17 | #include 18 | using namespace std; 19 | int main(){ 20 | int n,i,a,b,c,x; 21 | cin >> n; 22 | for(i=1;i<=n;i++){ 23 | for(a=1;a<=i-1;a++) cout << " "; 24 | for(b=1;b<=i;b++) cout << "#"; 25 | int x= (4*n-2)-(2*(a+b-2)); 26 | for(c=1;c<=x;c++) cout << " "; 27 | for(b=1;b<=i;b++) cout << "#"; 28 | cout << endl; 29 | } 30 | for(i=n;i>=1;i--){ 31 | for(a=1;a<=i-1;a++) cout << " "; 32 | for(b=1;b<=i;b++) cout << "#"; 33 | int x= (4*n-2)-(4*i-2); 34 | for(c=1;c<=x;c++) cout << " "; 35 | for(b=1;b<=i;b++) cout << "#"; 36 | cout << endl; 37 | } 38 | return 0; 39 | } 40 | -------------------------------------------------------------------------------- /C++/Pattern printing/27LR_Half_Char_Pyramid.cpp: -------------------------------------------------------------------------------- 1 | // ABCDCBA 1-4 & 5-7 2 | // ABC CBA 1-3 & 5-7 3 | // AB BA 4 | // A A 5 | #include 6 | using namespace std; 7 | int main() 8 | { 9 | int n,a; 10 | cout << "\nEnter number of rows: "; 11 | cin >> n; 12 | for(int r=n; r>=1; r--) 13 | { 14 | for(int c=1; c<=2*n-1; c++) 15 | { 16 | if(c<=r) { 17 | cout << ((char)(64+c)) << " "; 18 | if(c==r) 19 | a = c; 20 | } 21 | else if(c>(2*n)-r && r == n) { 22 | --a; 23 | cout << ((char)(64+a)) << " "; 24 | } 25 | else if(c>=(2*n)-r) { 26 | cout << ((char)(64+a)) << " "; 27 | --a; 28 | } 29 | else { 30 | cout << " "; 31 | } 32 | } 33 | cout << endl; 34 | } 35 | return 0; 36 | } -------------------------------------------------------------------------------- /Numbers/DuckNumbers.java: -------------------------------------------------------------------------------- 1 | //Name- Suman Meher 2 | //Username- sumanmeher 3 | 4 | //DUCK NUMBERS: A number which has zeroes present in it, but there should be no zero present in the beginning of the number. 5 | //Ex: 7089,884602, etc. 6 | import java.util.Scanner; 7 | public class DuckNumbers { 8 | public static void main(String[] args) { 9 | Scanner sc = new Scanner(System.in); 10 | System.out.println("Enter a number: "); 11 | int digit, num = sc.nextInt(); 12 | boolean isDuckNumber = false; 13 | 14 | while (num != 0) { 15 | digit = num % 10; 16 | if (digit == 0){ 17 | isDuckNumber=true; 18 | break; 19 | } 20 | num = num / 10; 21 | } 22 | if(isDuckNumber){ 23 | System.out.println("A Duck Number"); 24 | }else{ 25 | System.out.println("NOT A Duck Number"); 26 | } 27 | sc.close(); 28 | } 29 | 30 | } 31 | -------------------------------------------------------------------------------- /C++/ContainerWithMostWater.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | int maxArea(vector& height) { 4 | int max = 0, area = 0, l = 0, r = 0; 5 | int n = height.size(); 6 | if (n < 2) 7 | return max; 8 | 9 | int left = 0, right = n - 1; 10 | 11 | while (left < right) 12 | { 13 | l = height[left]; 14 | r = height[right]; 15 | area = min(l, r) * (right - left); 16 | if (max < area) 17 | max = area; 18 | 19 | if (l < r) 20 | { 21 | left++; 22 | while (left < right && height[left] <= l) 23 | left++; 24 | } 25 | else 26 | { 27 | right--; 28 | while (left < right && height[right] <= r) 29 | right--; 30 | } 31 | } 32 | 33 | return max; 34 | } 35 | }; 36 | -------------------------------------------------------------------------------- /C++/Pattern printing/Print_the_Pattern.cpp: -------------------------------------------------------------------------------- 1 | // 1*2*3*10*11*12 2 | // --4*5*8*9 3 | // ----6*7 4 | 5 | class Solution{ 6 | public: 7 | vector pattern(int n){ 8 | vector ans; 9 | int k=1; 10 | string a; 11 | for (int i = 0; i < n; i++) 12 | { 13 | a.clear(); 14 | for (int j = 0; j =0;i--){ 28 | a.clear(); 29 | for(int j=0;j 2 | using namespace std; 3 | 4 | int maxi(int arr[], int n) 5 | { 6 | int m = 0; 7 | for (int i = 0; i < n; i++) 8 | { 9 | int count = 0; 10 | for (int j = 0; j < n; j++) 11 | { 12 | if (arr[i] == arr[j]) 13 | { 14 | count++; 15 | } 16 | } 17 | if (m < count) 18 | { 19 | m = count; 20 | } 21 | } 22 | return m; 23 | } 24 | int main() 25 | { 26 | int arr[100]; 27 | // your code goes here 28 | int t; 29 | cin >> t; 30 | for (int i = 1; i <= t; i++) 31 | { 32 | int arr[100]; 33 | int n; 34 | cin >> n; 35 | for (int i = 0; i < n; i++) 36 | { 37 | cin >> arr[i]; 38 | 39 | 40 | 41 | 42 | } 43 | int ma = maxi(arr, n); 44 | cout << (n - ma) << endl; 45 | } 46 | return 0; 47 | } 48 | -------------------------------------------------------------------------------- /C++/reverse_an_array.cpp: -------------------------------------------------------------------------------- 1 | //Reverse an array in C++ 2 | #include 3 | using namespace std; 4 | int main() 5 | { 6 | int arr[100], size, i, j, temp; 7 | cout<<"\n Enter Array Size : "; 8 | cin>>size; 9 | cout<<"\n Enter Array Elements : \n"; 10 | for(i=0; i>arr[i]; 13 | } 14 | cout<<"\n Array Elements : \n\n"; 15 | for(i=0; i 0; temp = temp / 10) { 17 | fact = 1; 18 | rem = temp % 10; 19 | 20 | for (int i = 1; i <= rem; i++) { 21 | fact = fact * i; 22 | } 23 | sum = sum + fact; 24 | } 25 | 26 | if (sum == petnum) { 27 | System.out.println("A Peterson Number"); 28 | } else { 29 | System.out.println("Not A Peterson Number"); 30 | } 31 | sc.close(); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /Out_of_boundary_paths.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | int t[51][51][51]; 4 | int mod = pow(10,9) + 7; 5 | int solve(int m, int n, int maxMove, int startRow, int startColumn) { 6 | if(startRow<0 || startRow>=m || startColumn<0 || startColumn>=n) return 1; 7 | if(maxMove<=0) return 0; 8 | if(t[maxMove][startRow][startColumn]!=-1) return t[maxMove][startRow][startColumn]%mod; 9 | int ans = 0; 10 | ans= (ans + solve(m,n,maxMove - 1,startRow - 1,startColumn))%mod; 11 | ans = (ans+ solve(m,n,maxMove - 1,startRow + 1,startColumn))%mod; 12 | ans = (ans +solve(m,n,maxMove - 1,startRow ,startColumn - 1))%mod; 13 | ans = (ans +solve(m,n,maxMove - 1,startRow,startColumn + 1))%mod; 14 | return t[maxMove][startRow][startColumn] = (ans)%mod; 15 | } 16 | 17 | int findPaths(int m, int n, int maxMove, int startRow, int startColumn) { 18 | memset(t,-1,sizeof(t)); 19 | return solve(m,n,maxMove,startRow,startColumn)%mod; 20 | } 21 | }; 22 | -------------------------------------------------------------------------------- /C++/Pattern printing/27RL_Half_CharInvPyd.cpp: -------------------------------------------------------------------------------- 1 | // A B C D E D C B A Right-Left half Inverted Pyramid. 2 | // A B C D D C B A 3 | // A B C C B A 4 | // A B B A 5 | // A A 6 | #include 7 | using namespace std; 8 | int main() 9 | { 10 | int n,a; 11 | cout << "\nEnter number of rows: "; 12 | cin >> n; 13 | for(int r=n; r>=1; r--) 14 | { 15 | for(int c=1; c<=2*n-1; c++) 16 | { 17 | if(c<=r) { 18 | cout << ((char)(64+c)) << " "; 19 | if(c==r) 20 | a = c; 21 | } 22 | else if(c>(2*n)-r && r == n) { 23 | --a; 24 | cout << ((char)(64+a)) << " "; 25 | } 26 | else if(c>=(2*n)-r) { 27 | cout << ((char)(64+a)) << " "; 28 | --a; 29 | } 30 | else { 31 | cout << " "; 32 | } 33 | } 34 | cout << endl; 35 | } 36 | return 0; 37 | } -------------------------------------------------------------------------------- /C++/selection_sort.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | void selection(int array[], int n) 4 | { 5 | int i, j, position, count=0; 6 | int swap; 7 | for(i = 0; i < (n - 1); i++) 8 | { 9 | position=i; 10 | for(j = i + 1; j < n; j++) 11 | { 12 | if(array[position]>array[j]) 13 | position=j; 14 | count++; 15 | } 16 | if(position != i) 17 | { 18 | swap=array[i]; 19 | array[i]=array[position]; 20 | array[position]=swap; 21 | } 22 | } 23 | printf("Sorted Array: "); 24 | for(i = 0; i < n; i++) 25 | printf(" %d", array[i]); 26 | printf("\nComplexity: %d", count); 27 | } 28 | int main() 29 | { 30 | int array[100]; 31 | int n,i; 32 | printf("Enter number of elements:\n"); 33 | scanf("%d", &n); 34 | printf("Enter Number:\n", n); 35 | for(i = 0; i < n; i++) 36 | scanf("%d", &array[i]); 37 | selection(array,n); 38 | getch(); 39 | return 0; 40 | } 41 | -------------------------------------------------------------------------------- /Numbers/Magic Number.java: -------------------------------------------------------------------------------- 1 | //Name- Aradhy Mishra 2 | //Username- aradhymishra09 3 | 4 | //MAGIC NUMBER: If the sum of its digits recursively are calculated till a single digit if the single digit is 1. 5 | //Ex: 226 etc. 6 | 7 | import java.util.Scanner; 8 | 9 | public class MagicNumber 10 | { 11 | public static void main(String[] args) 12 | { 13 | int n, r = 1, num, sum = 0; 14 | Scanner sc = new Scanner(System.in); 15 | System.out.print("Enter number="); 16 | n = sc.nextInt(); 17 | num = n; 18 | while (num > 9) 19 | { 20 | while (num > 0) 21 | { 22 | r = num % 10; 23 | sum = sum + r; 24 | num = num / 10; 25 | } 26 | num = sum; 27 | sum = 0; 28 | } 29 | if (num == 1) 30 | { 31 | System.out.println("Magic Number"); 32 | } 33 | else 34 | { 35 | System.out.println("Not Magic Number"); 36 | } 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /C++/vector-pair/pair_1.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | using namespace std; 5 | 6 | bool myCompare(pair p1, pair p2) 7 | { 8 | return p1.first p;//pair is used to two different type data type 14 | p.first = 3;//accesing the elments for pair 15 | p.second = 'f'; 16 | //going to solve a question 17 | int arr[]={10, 16, 7 , 14 , 5 , 3, 12 , 9}; 18 | vector>v; 19 | 20 | for (int i = 0; i < (sizeof(arr)/sizeof(arr[0])); i++) 21 | { 22 | /* code */ 23 | v.push_back(make_pair(arr[i],i)); 24 | 25 | } 26 | 27 | sort(v.begin(), v.end(), myCompare); 28 | for (int i = 0; i < v.size(); i++) 29 | { 30 | /* code */ 31 | arr[v[i].second]= i; 32 | } 33 | 34 | for (int i = 0; i < v.size(); i++) 35 | { 36 | /* code */ 37 | cout<> fourSum(vector& nums, int target) { 6 | sort(nums.begin(),nums.end()); 7 | vector>v; 8 | int n=nums.size(); 9 | set>s; 10 | for(int i=0;i 2 | using namespace std; 3 | void heapify(int arr[], int N, int i) 4 | { 5 | int largest = i; 6 | int l = 2 * i + 1; 7 | int r = 2 * i + 2; 8 | if (l < N && arr[l] > arr[largest]) 9 | largest = l; 10 | if (r < N && arr[r] > arr[largest]) 11 | largest = r; 12 | if (largest != i) { 13 | swap(arr[i], arr[largest]); 14 | heapify(arr, N, largest); 15 | } 16 | } 17 | void heapSort(int arr[], int N) 18 | { 19 | for (int i = N / 2 - 1; i >= 0; i--) 20 | heapify(arr, N, i); 21 | for (int i = N - 1; i > 0; i--) { 22 | swap(arr[0], arr[i]); 23 | heapify(arr, i, 0); 24 | } 25 | } 26 | void printArray(int arr[], int N) 27 | { 28 | for (int i = 0; i < N; ++i) 29 | cout << arr[i] << " "; 30 | cout << "\n"; 31 | } 32 | int main() 33 | { 34 | int arr[] = { 12, 11, 13, 5, 6, 7 }; 35 | int N = sizeof(arr) / sizeof(arr[0]); 36 | heapSort(arr, N); 37 | 38 | cout << "Sorted array is \n"; 39 | printArray(arr, N); 40 | } 41 | -------------------------------------------------------------------------------- /C++/Pattern printing/18Right_Half_Pyramid.cpp: -------------------------------------------------------------------------------- 1 | // // * 2 | // // * * 3 | // // * * * 4 | // // * * * * 5 | // #include 6 | // using namespace std; 7 | // int main() 8 | // { 9 | // int r; 10 | // cout << "\nHow many row you want to print: "; 11 | // cin >> r; 12 | // for(int i = (r-1); i>=0; i--) 13 | // { 14 | // for(int spc=i; spc>0; spc--) 15 | // { 16 | // cout << " "; 17 | // } 18 | // for(int j=r; j>i; j--) 19 | // { 20 | // cout << " *"; 21 | // } 22 | // cout << "\n"; 23 | // } 24 | // } 25 | // * 26 | // * * 27 | // * * * 28 | // * * * * 29 | #include 30 | using namespace std; 31 | 32 | int main(int argc, char **argv){ 33 | int n; 34 | cin >> n; 35 | 36 | //write your code here 37 | for(int r=1; r<=n; r++) 38 | { 39 | for(int spc=1; spc<=n-r; spc++) 40 | cout << " "; 41 | 42 | for(int c=n; c>n-r; c--) 43 | cout << " *"; 44 | 45 | cout << "\n"; 46 | } 47 | } -------------------------------------------------------------------------------- /Numbers/HappyNumber.java: -------------------------------------------------------------------------------- 1 | //Name- Supravat Dwari 2 | //Username- SupravatDwari 3 | 4 | //HAPPY NUMBER: A number is called Happy number if a given number base that eventually reaches 1 when iterated over the perfect digital invariant function for. 5 | //Ex: 31 etc. 6 | 7 | import java.util.Scanner; 8 | 9 | public class HappyNumber 10 | { 11 | public static void main(String[] args) 12 | { 13 | int n, r = 1, num, sum = 0; 14 | Scanner sc = new Scanner(System.in); 15 | System.out.print("Enter number:"); 16 | n = sc.nextInt(); 17 | num = n; 18 | while (num > 9) 19 | { 20 | while (num > 0) 21 | { 22 | r = num % 10; 23 | sum = sum + (r * r); 24 | num = num / 10; 25 | } 26 | num = sum; 27 | sum = 0; 28 | } 29 | if (num == 1) 30 | { 31 | System.out.println("Happy Number"); 32 | } 33 | else 34 | { 35 | System.out.println("Not Happy Number"); 36 | } 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /C++/Reverse Nodes in k-Group.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * Definition for singly-linked list. 3 | * struct ListNode { 4 | * int val; 5 | * ListNode *next; 6 | * ListNode() : val(0), next(nullptr) {} 7 | * ListNode(int x) : val(x), next(nullptr) {} 8 | * ListNode(int x, ListNode *next) : val(x), next(next) {} 9 | * }; 10 | */ 11 | class Solution { 12 | public: 13 | ListNode* reverseKGroup(ListNode* head, int k) { 14 | 15 | ListNode* cursor = head; 16 | for(int i = 0; i < k; i++){ 17 | if(cursor == nullptr) return head; 18 | cursor = cursor->next; 19 | } 20 | ListNode* curr=head; 21 | ListNode* prev=NULL; 22 | ListNode* forward=NULL; 23 | int count=0; 24 | while(curr!=NULL && countnext; 27 | curr->next=prev; 28 | prev=curr; 29 | curr=forward; 30 | count++; 31 | 32 | } 33 | if(forward!=NULL) 34 | { 35 | head->next=reverseKGroup(forward,k); 36 | } 37 | 38 | return prev; 39 | } 40 | }; -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2022 Subham Das 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 | -------------------------------------------------------------------------------- /C++/Median of Two Sorted Arrays.cpp: -------------------------------------------------------------------------------- 1 | //Problem Link : https://leetcode.com/problems/median-of-two-sorted-arrays/ 2 | 3 | #include 4 | using namespace std; 5 | 6 | float median(int nums1[],int nums2[],int m,int n) { 7 | int finalArray[n+m]; 8 | int i=0,j=0,k=0; 9 | while(i 2 | using namespace std; 3 | bool ispossible(int arr[], int m,int n,int mid){ 4 | int stucount=1; 5 | int pagecount =0; 6 | for (int i = 0; i < n; i++) 7 | { 8 | 9 | if ((pagecount+arr[i])<=mid) 10 | { 11 | pagecount+=arr[i]; 12 | } 13 | else{ 14 | stucount++; 15 | if (stucount>m || arr[i]>mid) 16 | { 17 | return false; 18 | } 19 | pagecount=arr[i]; 20 | } 21 | } 22 | return true; 23 | } 24 | int findallocation(int arr[],int n,int m){ 25 | int s=0,sum=0; 26 | int ans=-1; 27 | for (int i = 0; i < n; i++) 28 | { 29 | sum+=arr[i]; 30 | } 31 | int e=sum; 32 | int mid=s+(e-s)/2; 33 | while (s>& b,int i,int j, string w,int k) { 6 | if(k==w.size()-1) 7 | return true; 8 | 9 | b[i][j]-=65;//visited 10 | if(i-1>=0 && w[k+1]==b[i-1][j] && search(b,i-1,j,w,k+1)) 11 | return true; 12 | if(i+1=0 && w[k+1]==b[i][j-1] && search(b,i,j-1,w,k+1)) 15 | return true; 16 | if(j+1>& b, string w) { 24 | r=b.size(); 25 | c=b[0].size(); 26 | 27 | for(int i = 0; i < r; i++){ 28 | for(int j = 0; j < c; j++) 29 | if(b[i][j]==w[0] && search(b,i,j,w,0)) 30 | return true; 31 | } 32 | 33 | return false; 34 | 35 | } 36 | }; 37 | -------------------------------------------------------------------------------- /Wiggle_subsequence.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | int dp[1001][1002][2]; 4 | int solve(vector& nums,int n,int lastnum,int inc){ 5 | if(n<=0) return 0; 6 | if(dp[n][lastnum][inc]!=-1) return dp[n][lastnum][inc]; 7 | if(inc){ 8 | if(nums[n-1]lastnum){ 17 | int a = solve(nums,n-1,nums[n-1],1) + 1; 18 | int b = solve(nums,n-1,lastnum,inc); 19 | return dp[n][lastnum][inc] = max(a,b); 20 | }else{ 21 | return dp[n][lastnum][inc] = solve(nums,n-1,lastnum,inc); 22 | } 23 | } 24 | } 25 | 26 | int wiggleMaxLength(vector& nums) { 27 | int n = nums.size(); 28 | memset(dp,-1,sizeof(dp)); 29 | int a = solve(nums,n,0,0); 30 | int b = solve(nums,n,1001,1); 31 | return max(a,b); 32 | } 33 | }; 34 | -------------------------------------------------------------------------------- /C++/Brick sort.cpp: -------------------------------------------------------------------------------- 1 | // A C++ Program to implement Odd-Even / Brick Sort 2 | #include 3 | using namespace std; 4 | 5 | // A function to sort the algorithm using Odd Even sort 6 | void oddEvenSort(int arr[], int n) 7 | { 8 | bool isSorted = false; // Initially array is unsorted 9 | 10 | while (!isSorted) 11 | { 12 | isSorted = true; 13 | 14 | // Perform Bubble sort on odd indexed element 15 | for (int i=1; i<=n-2; i=i+2) 16 | { 17 | if (arr[i] > arr[i+1]) 18 | { 19 | swap(arr[i], arr[i+1]); 20 | isSorted = false; 21 | } 22 | } 23 | 24 | // Perform Bubble sort on even indexed element 25 | for (int i=0; i<=n-2; i=i+2) 26 | { 27 | if (arr[i] > arr[i+1]) 28 | { 29 | swap(arr[i], arr[i+1]); 30 | isSorted = false; 31 | } 32 | } 33 | } 34 | 35 | return; 36 | } 37 | 38 | // A utility function ot print an array of size n 39 | void printArray(int arr[], int n) 40 | { 41 | for (int i=0; i < n; i++) 42 | cout << arr[i] << " "; 43 | cout << "\n"; 44 | } 45 | 46 | // Driver program to test above functions. 47 | int main() 48 | { 49 | int arr[] = {34, 2, 10, -9}; 50 | int n = sizeof(arr)/sizeof(arr[0]); 51 | 52 | oddEvenSort(arr, n); 53 | printArray(arr, n); 54 | 55 | return (0); 56 | } 57 | -------------------------------------------------------------------------------- /Numbers/EvilNumbers.java: -------------------------------------------------------------------------------- 1 | //Name- Suman Meher 2 | //Username- sumanmeher 3 | 4 | //EVIL NUMBERs: A special positive whole number that has an even number of 1's in its binary equivalent. 5 | import java.util.Scanner; 6 | 7 | public class EvilNumbers { 8 | public static void main(String args[]) { 9 | Scanner sc = new Scanner(System.in); 10 | System.out.print("Enter a positive number: "); 11 | int n = sc.nextInt(); 12 | if (n < 0) { 13 | System.out.println("Invalid Input"); 14 | return; 15 | } 16 | 17 | int count = 0; 18 | int p = 0; 19 | int binNum = 0; 20 | 21 | while (n > 0) { 22 | int d = n % 2; 23 | if (d == 1) 24 | count++; 25 | binNum += (int)(d * Math.pow(10, p)); 26 | p++; 27 | n /= 2; 28 | } 29 | 30 | System.out.println("Binary Equivalent: " + binNum); 31 | System.out.println("No. of 1's: " + count); 32 | 33 | if (count % 2 == 0) 34 | System.out.println("Evil Number"); 35 | else 36 | System.out.println("Not an Evil Number"); 37 | 38 | sc.close(); 39 | } 40 | } 41 | 42 | -------------------------------------------------------------------------------- /C++/Game of Life.cpp: -------------------------------------------------------------------------------- 1 | // Problem Link : https://leetcode.com/problems/game-of-life/ 2 | 3 | class Solution { 4 | public: 5 | void gameOfLife(vector>& a) { 6 | int n=a.size(); 7 | int m=a[0].size(); 8 | 9 | 10 | for(int i=0;i=0 ? a[i-1][j]&1:0 ; 13 | int down=i+1=0?a[i][j-1]&1:0; 15 | int right=j+1=0 and j-1>=0 ?a[i-1][j-1]&1:0; 17 | int topr=i-1>=0 and j+1=0 ?a[i+1][j-1]&1:0; 19 | int br=i+1=2 and count<=3) 24 | a[i][j]=3; 25 | 26 | if(a[i][j]==0 and count==3) 27 | a[i][j]=2; 28 | } 29 | 30 | } 31 | 32 | 33 | for(int i=0;i>=1; 36 | } 37 | }; 38 | -------------------------------------------------------------------------------- /C++/Pattern printing/0-1_Knapsack.cpp: -------------------------------------------------------------------------------- 1 | /* A Naive recursive implementation of 2 | 0-1 Knapsack problem */ 3 | #include 4 | using namespace std; 5 | 6 | // A utility function that returns 7 | // maximum of two integers 8 | int max(int a, int b) { return (a > b) ? a : b; } 9 | 10 | // Returns the maximum value that 11 | // can be put in a knapsack of capacity W 12 | int knapSack(int W, int wt[], int val[], int n) 13 | { 14 | 15 | // Base Case 16 | if (n == 0 || W == 0) 17 | return 0; 18 | 19 | // If weight of the nth item is more 20 | // than Knapsack capacity W, then 21 | // this item cannot be included 22 | // in the optimal solution 23 | if (wt[n - 1] > W) 24 | return knapSack(W, wt, val, n - 1); 25 | 26 | // Return the maximum of two cases: 27 | // (1) nth item included 28 | // (2) not included 29 | else 30 | return max( 31 | val[n - 1] 32 | + knapSack(W - wt[n - 1], 33 | wt, val, n - 1), 34 | knapSack(W, wt, val, n - 1)); 35 | } 36 | 37 | // Driver code 38 | int main() 39 | { 40 | int val[] = { 60, 100, 120 }; 41 | int wt[] = { 10, 20, 30 }; 42 | int W = 50; 43 | int n = sizeof(val) / sizeof(val[0]); 44 | cout << knapSack(W, wt, val, n); 45 | return 0; 46 | } 47 | 48 | 49 | -------------------------------------------------------------------------------- /Palindrome_Flipping.java: -------------------------------------------------------------------------------- 1 | /* package codechef; // don't place package name! */ 2 | 3 | import java.util.*; 4 | import java.lang.*; 5 | import java.io.*; 6 | 7 | /* Name of the class has to be "Main" only if the class is public. */ 8 | class Codechef 9 | { 10 | public static void main (String[] args) throws java.lang.Exception 11 | { 12 | // your code goes here 13 | try{ 14 | Scanner sc = new Scanner(System.in); 15 | int T,N,i,j,m,n; 16 | T=sc.nextInt(); 17 | for(i=0;i 4 | using namespace std; 5 | 6 | vector < pair < int, int >> merge(vector < pair < int, int >> & arr) { 7 | 8 | int n = arr.size(); 9 | sort(arr.begin(), arr.end()); 10 | vector < pair < int, int >> ans; 11 | 12 | for (int i = 0; i < n; i++) { 13 | int start = arr[i].first, end = arr[i].second; 14 | 15 | 16 | if (!ans.empty()) { 17 | if (start <= ans.back().second) { 18 | continue; 19 | } 20 | } 21 | 22 | for (int j = i + 1; j < n; j++) { 23 | if (arr[j].first <= end) { 24 | end = max(end, arr[j].second); 25 | } 26 | } 27 | 28 | end = max(end, arr[i].second); 29 | 30 | ans.push_back({start, end}); 31 | } 32 | 33 | return ans; 34 | } 35 | 36 | int main() { 37 | vector < pair < int, int >> arr; 38 | arr = {{1,3},{2,4},{2,6},{8,9},{8,10},{9,11},{15,18},{16,17}}; 39 | vector < pair < int, int >> ans = merge(arr); 40 | 41 | cout << "Merged Overlapping Intervals are " << endl; 42 | 43 | for (auto it: ans) { 44 | cout << it.first << " " << it.second << "\n"; 45 | } 46 | } -------------------------------------------------------------------------------- /C++/spiralordermatrix.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Name : Rounak Ghosh 3 | Username : Rounak-Ghosh 4 | About : 4th year undergrad student at GCETTB 5 | */ 6 | 7 | #include 8 | using namespace std; 9 | 10 | int main() 11 | { 12 | int n,m; 13 | cin>>n>>m; 14 | 15 | int arr[n][m]; 16 | 17 | for(int i=0; i>arr[i][j]; 20 | 21 | int row_start=0, row_end=n-1, col_start=0, col_end=m-1; 22 | 23 | while(row_start <= row_end && col_start <= col_end) 24 | { 25 | // for row start 26 | for(int col = col_start; col <= col_end; col++) 27 | cout << arr[row_start][col] << " "; 28 | row_start++; 29 | 30 | // for col end 31 | for(int row = row_start; row <= row_end; row++) 32 | cout << arr[row][col_end] << " "; 33 | col_end--; 34 | 35 | // for row end 36 | for(int col = col_end; col >= col_start; col--) 37 | cout << arr[row_end][col] << " "; 38 | row_end--; 39 | 40 | // for col start 41 | for(int row = row_end; row >= row_start; row--) 42 | cout << arr[row][col_start] << " "; 43 | col_start++; 44 | } 45 | 46 | return 0; 47 | } -------------------------------------------------------------------------------- /C++/Singly_LinkedList.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | //sll structure 6 | 7 | class Node{ 8 | public: 9 | int data; 10 | Node* next; 11 | }; 12 | 13 | //insertion at end 14 | 15 | void insertEnd(Node* head,int data){ 16 | 17 | Node* temp = new Node(); 18 | Node* curr =(head); 19 | temp->data = data; 20 | temp->next = NULL; 21 | 22 | if(curr==NULL){ 23 | (head) = temp; 24 | return; 25 | } 26 | 27 | while(curr->next != NULL){ 28 | curr=curr->next; 29 | } 30 | curr->next=temp; 31 | return; 32 | } 33 | 34 | //insertion at begining 35 | 36 | void insertBegin(Node* &head,int data){ 37 | 38 | Node* temp = new Node(); 39 | temp->data = data; 40 | 41 | 42 | if(head==NULL){ 43 | head = temp; 44 | return; 45 | } 46 | 47 | temp->next = head; 48 | head = temp; 49 | 50 | } 51 | 52 | //traversal of list 53 | 54 | void traverse(Node* head){ 55 | 56 | if (head==NULL) cout<<"list is empty"; 57 | 58 | while(head!=NULL){ 59 | cout<data<<" -> "; 60 | head=head->next; 61 | } 62 | } 63 | int main(int argc, char const *argv[]) 64 | { 65 | Node* slist = new Node(); 66 | insertEnd(slist,2); 67 | insertBegin(slist,3); 68 | insertEnd(slist,4); 69 | insertBegin(slist,3); 70 | traverse(slist); 71 | return 0; 72 | } -------------------------------------------------------------------------------- /Simplify_Path.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | string simplifyPath(string path) { 4 | 5 | stack st; 6 | string res; 7 | 8 | for(int i = 0; i 4 | 5 | using namespace std; 6 | class Solution { 7 | public: 8 | void findCombination(int ind, int target, vector < int > & arr, vector < vector < int >> & ans, vector < int > & ds) { 9 | if (ind == arr.size()) { 10 | if (target == 0) { 11 | ans.push_back(ds); 12 | } 13 | return; 14 | } 15 | // pick up the element 16 | if (arr[ind] <= target) { 17 | ds.push_back(arr[ind]); 18 | findCombination(ind, target - arr[ind], arr, ans, ds); 19 | ds.pop_back(); 20 | } 21 | 22 | findCombination(ind + 1, target, arr, ans, ds); 23 | 24 | } 25 | public: 26 | vector < vector < int >> combinationSum(vector < int > & candidates, int target) { 27 | vector < vector < int >> ans; 28 | vector < int > ds; 29 | findCombination(0, target, candidates, ans, ds); 30 | return ans; 31 | } 32 | }; 33 | int main() { 34 | Solution obj; 35 | vector < int > v {2,3,6,7}; 36 | int target = 7; 37 | 38 | vector < vector < int >> ans = obj.combinationSum(v, target); 39 | cout << "Combinations are: " << endl; 40 | for (int i = 0; i < ans.size(); i++) { 41 | for (int j = 0; j < ans[i].size(); j++) 42 | cout << ans[i][j] << " "; 43 | cout << endl; 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /C++/vertical_order_bt.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Name : Rounak Ghosh 3 | Username : Rounak-Ghosh 4 | About : 4th year undergrad student at GCETTB 5 | */ 6 | 7 | #include 8 | #include 9 | #include 10 | using namespace std; 11 | 12 | struct Node 13 | { 14 | int key; 15 | struct Node *left, *right; 16 | 17 | Node(int val) 18 | { 19 | key = val; 20 | left = NULL; 21 | right = NULL; 22 | } 23 | }; 24 | 25 | void getVerticalOrder(Node* root, int hdis, map> &m) 26 | { 27 | if(root == NULL) 28 | return; 29 | 30 | m[hdis].push_back(root->key); 31 | getVerticalOrder(root->left, hdis-1, m); 32 | getVerticalOrder(root->right, hdis+1, m); 33 | } 34 | 35 | int main() 36 | { 37 | Node *root = new Node(10); 38 | root->left = new Node(7); 39 | root->right = new Node(4); 40 | root->left->left = new Node(3); 41 | root->left->right = new Node(11); 42 | root->right->left = new Node(14); 43 | root->right->right = new Node(6); 44 | 45 | map> m; 46 | int hdis = 0; 47 | 48 | getVerticalOrder(root, hdis, m); 49 | 50 | map> :: iterator it; 51 | for(it = m.begin(); it!=m.end(); it++) 52 | { 53 | for(int i=0; i<(it->second).size(); i++) 54 | cout << (it->second)[i] << " "; 55 | cout << endl; 56 | } 57 | return 0; 58 | } -------------------------------------------------------------------------------- /C++/3–Partition Problem.cpp: -------------------------------------------------------------------------------- 1 | // Solution of 3 - partition Problem 2 | #include 3 | #include 4 | #include 5 | using namespace std; 6 | 7 | 8 | bool subsetSum(vector const &S, int n, int a, int b, int c) 9 | { 10 | 11 | if (a == 0 && b == 0 && c == 0) { 12 | return true; 13 | } 14 | 15 | 16 | if (n < 0) { 17 | return false; 18 | } 19 | 20 | 21 | bool A = false; 22 | if (a - S[n] >= 0) { 23 | A = subsetSum(S, n - 1, a - S[n], b, c); 24 | } 25 | 26 | 27 | bool B = false; 28 | if (!A && (b - S[n] >= 0)) { 29 | B = subsetSum(S, n - 1, a, b - S[n], c); 30 | } 31 | 32 | 33 | bool C = false; 34 | if ((!A && !B) && (c - S[n] >= 0)) { 35 | C = subsetSum(S, n - 1, a, b, c - S[n]); 36 | } 37 | 38 | 39 | return A || B || C; 40 | } 41 | 42 | 43 | bool partition(vector const &S) 44 | { 45 | 46 | int n = S.size(); 47 | 48 | 49 | if (n < 3) { 50 | return false; 51 | } 52 | 53 | 54 | int sum = accumulate(S.begin(), S.end(), 0); 55 | 56 | 57 | return !(sum % 3) && subsetSum(S, n - 1, sum/3, sum/3, sum/3); 58 | } 59 | 60 | int main() 61 | { 62 | 63 | vector S = { 7, 3, 2, 1, 5, 4, 8 }; 64 | 65 | if (partition(S)) { 66 | cout << "Set can be partitioned"; 67 | } 68 | else { 69 | cout << "Set cannot be partitioned"; 70 | } 71 | 72 | return 0; 73 | } 74 | 75 | -------------------------------------------------------------------------------- /C++/Aggressive_Cows.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | bool isPossible(vector& stalls , int n , int k , int mid) 5 | { 6 | int cowsCount = 1; 7 | int cowsDistance = stalls[0]; 8 | for(int i= 0 ; i< n ;i++) 9 | { 10 | if(stalls[i] - cowsDistance >= mid) 11 | { 12 | cowsCount++; 13 | if(cowsCount == k) 14 | { 15 | return true; 16 | } 17 | cowsDistance = stalls[i]; 18 | } 19 | 20 | } 21 | return false; 22 | } 23 | 24 | int aggresiveCows(vector &stalls , int n , int k) 25 | { 26 | sort(stalls.begin() , stalls.end()); 27 | int start = 0; 28 | int maxi = -1; 29 | for(int i=0 ; i> n >> k; 53 | vector arr; 54 | for(int i=0 ;i> x; 57 | arr.push_back(x); 58 | } 59 | int ans = aggresiveCows(arr , n , k); 60 | cout << ans; 61 | return 0; 62 | } 63 | -------------------------------------------------------------------------------- /opensource/NewYearCountdown.JS: -------------------------------------------------------------------------------- 1 | 2 | #himanshukumarlenka 3 | #Created New Year Countdown 2023 Using Javascript 4 | 5 |
6 |
7 |
8 |

New Year Countdown

9 |
10 |
11 |
12 |
13 |
00
14 |
15 |
16 |
Days
17 |
18 |
19 |
20 |
21 |
22 |
23 |
00
24 |
25 |
26 |
Hours
27 |
28 |
29 |
30 |
31 |
32 |
33 |
00
34 |
35 |
36 |
Minutes
37 |
38 |
39 |
40 |
41 |
42 |
43 |
00
44 |
45 |
46 |
Seconds
47 |
48 |
49 |
50 |
51 |
52 |
-------------------------------------------------------------------------------- /C++/two_pointer_technique.cpp: -------------------------------------------------------------------------------- 1 | // C++ Program Illustrating Naive Approach to 2 | // Find if There is a Pair in A[0..N-1] with Given Sum 3 | // Using Two-pointers Technique 4 | 5 | // Importing required libraries 6 | #include 7 | 8 | using namespace std; 9 | 10 | // Two pointer technique based solution to find 11 | // if there is a pair in A[0..N-1] with a given sum. 12 | int isPairSum(int A[], int N, int X) 13 | { 14 | // represents first pointer 15 | int i = 0; 16 | 17 | // represents second pointer 18 | int j = N - 1; 19 | 20 | while (i < j) { 21 | 22 | // If we find a pair 23 | if (A[i] + A[j] == X) 24 | return 1; 25 | 26 | // If sum of elements at current 27 | // pointers is less, we move towards 28 | // higher values by doing i++ 29 | else if (A[i] + A[j] < X) 30 | i++; 31 | 32 | // If sum of elements at current 33 | // pointers is more, we move towards 34 | // lower values by doing j-- 35 | else 36 | j--; 37 | } 38 | return 0; 39 | } 40 | 41 | // Driver code 42 | int main() 43 | { 44 | // array declaration 45 | int arr[] = { 2, 3, 5, 8, 9, 10, 11 }; 46 | 47 | // value to search 48 | int val = 17; 49 | 50 | // size of the array 51 | int arrSize = *(&arr + 1) - arr; 52 | 53 | // array should be sorted before using two-pointer technique 54 | sort(arr, arr+7); 55 | 56 | // Function call 57 | if((bool)isPairSum(arr, arrSize, val)==1) 58 | { 59 | cout<<"Valid Pair present"; 60 | } 61 | else 62 | { 63 | cout<<"No Valid Pair found"; 64 | } 65 | 66 | return 0; 67 | } -------------------------------------------------------------------------------- /C++/IdenticalTrees.cpp: -------------------------------------------------------------------------------- 1 | // C++ program to see if two trees are identical 2 | #include 3 | using namespace std; 4 | 5 | /* A binary tree node has data, pointer to left child 6 | and a pointer to right child */ 7 | class node { 8 | public: 9 | int data; 10 | node* left; 11 | node* right; 12 | }; 13 | 14 | /* Helper function that allocates a new node with the 15 | given data and NULL left and right pointers. */ 16 | node* newNode(int data) 17 | { 18 | node* Node = new node(); 19 | Node->data = data; 20 | Node->left = NULL; 21 | Node->right = NULL; 22 | 23 | return (Node); 24 | } 25 | 26 | /* Given two trees, return true if they are 27 | structurally identical */ 28 | int identicalTrees(node* a, node* b) 29 | { 30 | /*1. both empty */ 31 | if (a == NULL && b == NULL) 32 | return 1; 33 | 34 | /* 2. both non-empty -> compare them */ 35 | if (a != NULL && b != NULL) { 36 | return (a->data == b->data 37 | && identicalTrees(a->left, b->left) 38 | && identicalTrees(a->right, b->right)); 39 | } 40 | 41 | /* 3. one empty, one not -> false */ 42 | return 0; 43 | } 44 | 45 | /* Driver code*/ 46 | int main() 47 | { 48 | node* root1 = newNode(1); 49 | node* root2 = newNode(1); 50 | root1->left = newNode(2); 51 | root1->right = newNode(3); 52 | root1->left->left = newNode(4); 53 | root1->left->right = newNode(5); 54 | 55 | root2->left = newNode(2); 56 | root2->right = newNode(3); 57 | root2->left->left = newNode(4); 58 | root2->left->right = newNode(5); 59 | 60 | // Function call 61 | if (identicalTrees(root1, root2)) 62 | cout << "Both trees are identical."; 63 | else 64 | cout << "Trees are not identical."; 65 | 66 | return 0; 67 | } 68 | 69 | // This code is contributed by rathbhupendra 70 | -------------------------------------------------------------------------------- /C++/vector-pair/vector_1.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include//used to include vetor 3 | #include 4 | using namespace std; 5 | 6 | int main() 7 | { 8 | vector v; 9 | v.push_back(1);//used to push value in v vector(array) in the end 10 | v.push_back(2); 11 | v.push_back(3); 12 | 13 | for (int i = 0; i < v.size(); i++)//v.size() used for the size in vector 14 | { 15 | /* code */ 16 | cout<::iterator it;//let it is pointer for vector which points to every elments of vector from which 21 | //we can itrate through all over the vector 22 | for(it=v.begin(); it!=v.end(); it++) 23 | { 24 | cout<<*it< v2 (3, 50); 41 | //here we specify our vector elements like first one (3) is 42 | // decide to size means how many elements are there 43 | // second one decided 50 what value have three elements in case of similiar 44 | // 50 50 50 45 | 46 | swap(v, v2); 47 | //swap both vector's value 48 | //v= 50 50 50 and v2= 1 2 49 | for(auto element:v) 50 | { 51 | cout< 37 | #include 38 | using namespace std; 39 | 40 | const int mod = (int)1e9 + 7; 41 | 42 | int main() { 43 | 44 | cout<<"Enter the total number of coin denominations: "; 45 | int n; 46 | cin >> n; 47 | int *coins = new int[n]; 48 | for (int i = 0; i < n; i++) { 49 | cin >> coins[i]; 50 | } 51 | 52 | sort(coins, coins + n); 53 | 54 | cout<<"Enter the target value: "; 55 | int V; 56 | cin >> V; 57 | 58 | int dp[V + 1]; 59 | for (int i = 0; i <= V; i++)dp[i] = 0; 60 | 61 | dp[0] = 1; 62 | 63 | for (int i = 0; i < n; i++) { 64 | for (int j = coins[i]; j <= V; j++) { 65 | dp[j] = (dp[j] + dp[j - coins[i]]) % mod; 66 | } 67 | } 68 | cout << "Total number of ways to make target value are: " << dp[V] << endl; 69 | 70 | return 0; 71 | } 72 | -------------------------------------------------------------------------------- /C++/Digital Logarithm.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int main() 6 | { 7 | int t; 8 | cin >> t; 9 | while (t--) 10 | { 11 | int n; 12 | cin >> n; 13 | vector a(n); 14 | vector b(n); 15 | map mpa; 16 | map mpb; 17 | int c = 0; 18 | for (int i = 0; i < n; i++) 19 | { 20 | cin >> a[i]; 21 | mpa[a[i]]++; 22 | } 23 | for (int i = 0; i < n; i++) 24 | { 25 | cin >> b[i]; 26 | mpb[b[i]]++; 27 | } 28 | int x; 29 | for (int i = 0; i < n; i++) 30 | { 31 | if (mpb[a[i]] != 0) 32 | { 33 | x = min(mpb[a[i]], mpa[a[i]]); 34 | mpb[a[i]] -= x; 35 | mpa[a[i]] -= x; 36 | } 37 | } 38 | for (int i = 0; i < n; i++) 39 | { 40 | if (a[i] >= 10 && mpa[a[i]] != 0) 41 | { 42 | c += mpa[a[i]]; 43 | mpa[floor(log10(a[i])) + 1] += mpa[a[i]]; 44 | mpa[a[i]] = 0; 45 | } 46 | } 47 | for (int i = 0; i < n; i++) 48 | { 49 | if (mpb[b[i]] != 0 && b[i] >= 10) 50 | { 51 | c += mpb[b[i]]; 52 | mpb[floor(log10(b[i])) + 1] += mpb[b[i]]; 53 | mpb[b[i]] = 0; 54 | } 55 | } 56 | for (int i = 0; i < n; i++) 57 | { 58 | if (mpb[a[i]] != 0) 59 | { 60 | x = min(mpb[a[i]], mpa[a[i]]); 61 | mpb[a[i]] -= x; 62 | mpa[a[i]] -= x; 63 | } 64 | } 65 | for (int i = 2; i < 10; i++) 66 | { 67 | // cout< 4 | using namespace std; 5 | 6 | // Merge two subarrays L and M into arr 7 | void merge(int arr[], int p, int q, int r) { 8 | 9 | // Create L ← A[p..q] and M ← A[q+1..r] 10 | int n1 = q - p + 1; 11 | int n2 = r - q; 12 | 13 | int L[n1], M[n2]; 14 | 15 | for (int i = 0; i < n1; i++) 16 | L[i] = arr[p + i]; 17 | for (int j = 0; j < n2; j++) 18 | M[j] = arr[q + 1 + j]; 19 | 20 | // Maintain current index of sub-arrays and main array 21 | int i, j, k; 22 | i = 0; 23 | j = 0; 24 | k = p; 25 | 26 | // Until we reach either end of either L or M, pick larger among 27 | // elements L and M and place them in the correct position at A[p..r] 28 | while (i < n1 && j < n2) { 29 | if (L[i] <= M[j]) { 30 | arr[k] = L[i]; 31 | i++; 32 | } else { 33 | arr[k] = M[j]; 34 | j++; 35 | } 36 | k++; 37 | } 38 | 39 | // When we run out of elements in either L or M, 40 | // pick up the remaining elements and put in A[p..r] 41 | while (i < n1) { 42 | arr[k] = L[i]; 43 | i++; 44 | k++; 45 | } 46 | 47 | while (j < n2) { 48 | arr[k] = M[j]; 49 | j++; 50 | k++; 51 | } 52 | } 53 | 54 | // Divide the array into two subarrays, sort them and merge them 55 | void mergeSort(int arr[], int l, int r) { 56 | if (l < r) { 57 | // m is the point where the array is divided into two subarrays 58 | int m = l + (r - l) / 2; 59 | 60 | mergeSort(arr, l, m); 61 | mergeSort(arr, m + 1, r); 62 | 63 | // Merge the sorted subarrays 64 | merge(arr, l, m, r); 65 | } 66 | } 67 | 68 | // Print the array 69 | void printArray(int arr[], int size) { 70 | for (int i = 0; i < size; i++) 71 | cout << arr[i] << " "; 72 | cout << endl; 73 | } 74 | 75 | // Driver program 76 | int main() { 77 | int arr[] = {6, 5, 12, 10, 9, 1}; 78 | int size = sizeof(arr) / sizeof(arr[0]); 79 | 80 | mergeSort(arr, 0, size - 1); 81 | 82 | cout << "Sorted array: \n"; 83 | printArray(arr, size); 84 | return 0; 85 | } -------------------------------------------------------------------------------- /C++/BoxStacking.cpp: -------------------------------------------------------------------------------- 1 | //BoxStacking with C++ 2 | #include 3 | #include 4 | #include 5 | using namespace std; 6 | 7 | 8 | struct Box 9 | { 10 | 11 | int length, width, height; 12 | }; 13 | 14 | 15 | vector createAllRotations(vector const &boxes) 16 | { 17 | 18 | vector rotations; 19 | 20 | 21 | for (const Box &box: boxes) 22 | { 23 | 24 | rotations.push_back(box); 25 | 26 | 27 | rotations.push_back({ max(box.length, box.height), 28 | min(box.length, box.height), 29 | box.width }); 30 | 31 | 32 | rotations.push_back({ max(box.width, box.height), 33 | min(box.width, box.height), 34 | box.length }); 35 | } 36 | 37 | return rotations; 38 | } 39 | 40 | 41 | int findMaxHeight(vector const &boxes) 42 | { 43 | 44 | if (boxes.size() == 0) { 45 | return 0; 46 | } 47 | 48 | 49 | vector rotations = createAllRotations(boxes); 50 | 51 | 52 | sort(rotations.begin(), 53 | rotations.end(), 54 | [](const Box &x, const Box &y) { 55 | return x.length * x.width > y.length * y.width; 56 | }); 57 | 58 | 59 | vector max_height(rotations.size()); 60 | 61 | 62 | for (int i = 0; i < rotations.size(); i++) 63 | { 64 | for (int j = 0; j < i; j++) 65 | { 66 | 67 | if (rotations[i].length < rotations[j].length && 68 | rotations[i].width < rotations[j].width) { 69 | max_height[i] = max(max_height[i], max_height[j]); 70 | } 71 | } 72 | 73 | max_height[i] += rotations[i].height; 74 | } 75 | 76 | 77 | return *max_element(max_height.begin(), max_height.end()); 78 | } 79 | 80 | int main() 81 | { 82 | 83 | vector boxes { 84 | { 4, 2, 5 }, 85 | { 3, 1, 6 }, 86 | { 3, 2, 1 }, 87 | { 6, 3, 8 } 88 | }; 89 | 90 | cout << "The maximum height is " << findMaxHeight(boxes) << endl; 91 | 92 | return 0; 93 | } -------------------------------------------------------------------------------- /C++/Reverse_Linked_List_in_a_group_of_size_k.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | class node 5 | { 6 | public: 7 | int num; 8 | node *next; 9 | node(int a) 10 | { 11 | num = a; 12 | next = NULL; 13 | } 14 | }; 15 | 16 | void insertNode(node *&head, int val) 17 | { 18 | node *newNode = new node(val); 19 | if (head == NULL) 20 | { 21 | head = newNode; 22 | return; 23 | } 24 | 25 | node *temp = head; 26 | while (temp->next != NULL) 27 | temp = temp->next; 28 | 29 | temp->next = newNode; 30 | return; 31 | } 32 | 33 | int lengthOfLinkedList(node *head) 34 | { 35 | int length = 0; 36 | while (head != NULL) 37 | { 38 | ++length; 39 | head = head->next; 40 | } 41 | return length; 42 | } 43 | 44 | ListNode *reverseKGroup(ListNode *head, int k) 45 | { 46 | if (head == NULL || k == 1) 47 | return head; 48 | ListNode *dummy = new ListNode(0); 49 | dummy->next = head; 50 | ListNode *cur = dummy, *prev = dummy, *nex = dummy; 51 | int count = 0; 52 | while (cur->next != NULL) 53 | { 54 | cur = cur->next; 55 | count++; 56 | } 57 | while (count >= k) 58 | { 59 | cur = prev->next; 60 | nex = cur->next; 61 | for (int i = 1; i < k; i++) 62 | { 63 | cur->next = nex->next; 64 | nex->next = prev->next; 65 | prev->next = nex; 66 | nex = cur->next; 67 | } 68 | prev = cur; 69 | count -= k; 70 | } 71 | return dummy->next; 72 | } 73 | 74 | void printLinkedList(node *head) 75 | { 76 | while (head->next != NULL) 77 | { 78 | cout << head->num << "->"; 79 | head = head->next; 80 | } 81 | cout << head->num << "\n"; 82 | } 83 | 84 | int main() 85 | { 86 | node *head = NULL; 87 | int k = 3; 88 | insertNode(head, 1); 89 | insertNode(head, 2); 90 | insertNode(head, 3); 91 | insertNode(head, 4); 92 | insertNode(head, 5); 93 | insertNode(head, 6); 94 | insertNode(head, 7); 95 | insertNode(head, 8); 96 | 97 | cout << "Original Linked List: "; 98 | printLinkedList(head); 99 | cout << "After Reversal of k nodes: "; 100 | node *newHead = reverseKNodes(head, k); 101 | printLinkedList(newHead); 102 | 103 | return 0; 104 | } -------------------------------------------------------------------------------- /C++/Number of Enclaves.cpp: -------------------------------------------------------------------------------- 1 | // Problem Link : https://leetcode.com/problems/number-of-enclaves/ 2 | 3 | #include 4 | using namespace std; 5 | 6 | class Solution { 7 | public: 8 | int numberOfEnclaves(vector> &grid) 9 | { 10 | queue> q; 11 | int n = grid.size(); 12 | int m = grid[0].size(); 13 | int vis[n][m] = {0}; 14 | 15 | for(int i = 0;i=0 && nrow =0 && ncol < m 47 | && vis[nrow][ncol] == 0 && grid[nrow][ncol] == 1) 48 | { 49 | q.push({nrow, ncol}); 50 | vis[nrow][ncol] = 1; 51 | } 52 | } 53 | 54 | } 55 | 56 | int cnt = 0; 57 | for(int i = 0;i> grid 73 | { 74 | {0, 0, 0, 0}, 75 | {1, 0, 1, 0}, 76 | {0, 1, 1, 0}, 77 | {0, 0, 0, 0}}; 78 | 79 | Solution obj; 80 | cout << obj.numberOfEnclaves(grid) << endl; 81 | 82 | } -------------------------------------------------------------------------------- /C++/sudokuSolver.cpp: -------------------------------------------------------------------------------- 1 | /*Given a 9×9 incomplete sudoku, solve it such that it becomes valid sudoku. Valid sudoku has the following properties. 2 | 3 | 1. All the rows should be filled with numbers(1 – 9) exactly once. 4 | 2. All the columns should be filled with numbers(1 – 9) exactly once. 5 | 3. Each 3×3 submatrix should be filled with numbers(1 – 9) exactly once. 6 | 7 | Time Complexity: O(9(n ^ 2)) 8 | Space Complexity: O(1) 9 | */ 10 | 11 | #include 12 | 13 | #include 14 | 15 | using namespace std; 16 | 17 | bool isValid(vector < vector < char >> & board, int row, int col, char c) { 18 | for (int i = 0; i < 9; i++) { 19 | if (board[i][col] == c) 20 | return false; 21 | 22 | if (board[row][i] == c) 23 | return false; 24 | 25 | if (board[3 * (row / 3) + i / 3][3 * (col / 3) + i % 3] == c) 26 | return false; 27 | } 28 | return true; 29 | } 30 | 31 | bool solveSudoku(vector < vector < char >> & board) { 32 | for (int i = 0; i < board.size(); i++) { 33 | for (int j = 0; j < board[0].size(); j++) { 34 | if (board[i][j] == '.') { 35 | for (char c = '1'; c <= '9'; c++) { 36 | if (isValid(board, i, j, c)) { 37 | board[i][j] = c; 38 | 39 | if (solveSudoku(board)) 40 | return true; 41 | else 42 | board[i][j] = '.'; 43 | } 44 | } 45 | 46 | return false; 47 | } 48 | } 49 | } 50 | return true; 51 | } 52 | int main() { 53 | vector>board{ 54 | {'9', '5', '7', '.', '1', '3', '.', '8', '4'}, 55 | {'4', '8', '3', '.', '5', '7', '1', '.', '6'}, 56 | {'.', '1', '2', '.', '4', '9', '5', '3', '7'}, 57 | {'1', '7', '.', '3', '.', '4', '9', '.', '2'}, 58 | {'5', '.', '4', '9', '7', '.', '3', '6', '.'}, 59 | {'3', '.', '9', '5', '.', '8', '7', '.', '1'}, 60 | {'8', '4', '5', '7', '9', '.', '6', '1', '3'}, 61 | {'.', '9', '1', '.', '3', '6', '.', '7', '5'}, 62 | {'7', '.', '6', '1', '8', '5', '4', '.', '9'} 63 | }; 64 | 65 | solveSudoku(board); 66 | 67 | for(int i= 0; i< 9; i++){ 68 | for(int j= 0; j< 9; j++) 69 | cout< git clone "URL you just copied" 21 | 22 | e.g. git clone https://github.com/subhamtheone/HacktoberFest_22 23 | 24 | ### Step 4 Create a branch 25 | 26 | On your local machine go the project folder that you cloned and use following git command inside that folder 27 | 28 | create a new branch using below command 29 | 30 | git checkout -b 31 | 32 | e.g. git checkout -b 33 | 34 | ### Step 5 Lets make some contributions 35 | 36 | Make changes to files on your local machine work on the issue you're assigned. 37 | 38 | ### Step 6 Add Changes and Commit Changes 39 | 40 | Now we have to add changes that we made to the branch so for that we will run following command 41 | 42 | git add . 43 | 44 | Now we have to commit changes, commit message should always be clear, to commit use command below 45 | 46 | git commit -m "resolved the " 47 | 48 | ### Step 7 Push changes to GitHub 49 | 50 | Now we have to push the changes that we made to remote repository on specified branch to do so use command below 51 | 52 | git push origin 53 | 54 | name of branch is same as you created in step 3 55 | 56 | ### Step 8 Submit your changes for review 57 | 58 | Once you have pushed your code to GitHub, now it's time to create pull request, you will go to the repository click on compare and pull request and submit the pull request. 59 | 60 | Soon, we will be merging all your pull requests to the main branch of project and you will also get notification once your pull request is merged with existing code base. 61 | -------------------------------------------------------------------------------- /C++/anagramSum.cpp: -------------------------------------------------------------------------------- 1 | //function to find anagram sum or sum of Jumbled String 2 | 3 | 4 | int findSumOfJumbledString(string s) { 5 | unordered_map m; 6 | int sum = 0; 7 | for(int i = 0; i < s.size(); i++) 8 | { 9 | m[s[i]]++; 10 | } 11 | if(m.find('z')!=m.end()) //0 12 | { 13 | m['e']-=m['z']; 14 | m['r']-=m['z']; 15 | m['o']-=m['z']; 16 | m.erase('z'); 17 | } 18 | if(m.find('x')!=m.end()) //6 19 | { 20 | sum = sum + 6*m['x']; 21 | m['s']-=m['x']; 22 | m['i']-=m['x']; 23 | m.erase('x'); 24 | } 25 | if(m.find('g')!=m.end()) //8 26 | { 27 | sum = sum + 8*m['g']; 28 | m['e']-=m['g']; 29 | m['i']-=m['g']; 30 | m['h']-=m['g']; 31 | m['t']-=m['g']; 32 | m.erase('g'); 33 | } 34 | if(m.find('w')!=m.end()) //2 35 | { 36 | sum = sum + 2*m['w']; 37 | m['t']-=m['w']; 38 | m['o']-=m['w']; 39 | m.erase('w'); 40 | } 41 | if(m.find('u')!=m.end()) //4 42 | { 43 | sum = sum + 4*m['u']; 44 | m['f']-=m['u']; 45 | m['o']-=m['u']; 46 | m['r']-=m['u']; 47 | m.erase('u'); 48 | } 49 | if((m.find('h')!=m.end())) //3 50 | { 51 | sum = sum + 3*m['h']; 52 | m['t']-=m['h']; 53 | m['r']-=m['h']; 54 | m['e']-=m['h']; 55 | m['e']-=m['h']; 56 | m.erase('h'); 57 | } 58 | if((m.find('f')!=m.end())) //5 59 | { 60 | sum = sum + 5*m['f']; 61 | m['i']-=m['f']; 62 | m['v']-=m['f']; 63 | m['e']-=m['f']; 64 | m.erase('f'); 65 | } 66 | if((m.find('s')!=m.end())) 67 | { 68 | sum = sum + 7*m['s']; 69 | m['e']-=m['s']; 70 | m['v']-=m['s']; 71 | m['e']-=m['s']; 72 | m['n']-=m['s']; 73 | m.erase('s'); 74 | } 75 | if(m.find('o')!=m.end()) 76 | { 77 | sum = sum + m['o']; 78 | m['n']-=m['o']; 79 | m['e']-=m['o']; 80 | m.erase('o'); 81 | } 82 | if(m.find('i')!=m.end()) 83 | { 84 | sum = sum + 9*m['i']; 85 | m['n']-=m['i']; 86 | m['n']-=m['i']; 87 | m['e']-=m['i']; 88 | m.erase('i'); 89 | } 90 | return sum; 91 | } -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # 🎉HacktoberFest_2022🎉 2 | 3 | Celebrate **[Hacktoberfest](https://hacktoberfest.digitalocean.com/)** by getting involved in the open source community by completing some simple tasks in this project. 4 | 5 | This repository is open to all members of the GitHub community. Any member may contribute to this project without being a collaborator. 6 | 7 | **Leave a STAR ⭐ please. Will Be Helpful :)** 8 | 9 | P.S. Checkout this awesome `README.md` file 10 | 11 | **[https://github.com/subhamtheone/HacktoberFest_2022/](https://github.com/subhamtheone/HacktoberFest_2022/)** 12 | 13 | ## What is Hacktoberfest? 14 | 15 | A month-long celebration from October 1st - 31st sponsored by **[Digital Ocean](https://hacktoberfest.com/)** and **[GitHub](https://dev.to/this-is-learning/hacktoberfest-2022-is-almost-there-get-ready-4ifb)** to get people involved in **[Open Source](https://github.com/open-source)**. Create your very first pull request to any public repository on GitHub and contribute to the open source developer community. 16 | 17 | ![banner image](https://raw.githubusercontent.com/meerhamzadev/Hacktoberfest/main/assets/banner.jpg) 18 | 19 | ## 📌Video for help : 20 | - A Complete Hacktoberfest Guide : **(https://www.youtube.com/watch?v=AANiz18nuS0)** 21 | 22 | ## ✨Getting Started : 23 | - Register yourself on **[Hacktoberfest](https://hacktoberfest.digitalocean.com/)** 24 | - Fork this repository by clicking on the top right "fork" button 25 | - Now, clone this forked repository on to your local system 26 | 27 | ```terminal 28 | git clone https://github.com//HacktoberFest_2022.git 29 | ``` 30 | 31 | Example: git clone https://github.com/subhamtheone/HacktoberFest_2022.git 32 | 33 | - Create a new branch for yourself 34 | ```terminal 35 | git checkout -b 36 | ``` 37 | - Create a folder and name it as your contribution type 38 | - Include author_name and github username in each code by using comment-lines 39 | - Make your changes and put them in your folder 40 | - Commit and push them 41 | ```terminal 42 | git add . 43 | git commit -m "Commit Message" 44 | git push origin 45 | ``` 46 | - Make a PR to the original repository 47 | - Once we validate your contribution we will merge it 48 | - Congrats on your first PR 49 | - Repeat these steps 4 times to complete the tasks 50 | 51 | ## 📚Contribution Rules : 52 | ```text 53 | - You are allowed to make pull requests that break the rules. We just merge it ;) 54 | - Do NOT add any build steps e.g npm install (we want to keep this a simple static site) 55 | - Do NOT remove other content. 56 | - Styling/code can be pretty, ugly or stupid, big or small as long as it works 57 | - Try to keep pull requests small to minimize merge conflicts 58 | ``` 59 | **Happy Hacking !!** 60 | -------------------------------------------------------------------------------- /C++/countingPairsWithDifferentK.cpp: -------------------------------------------------------------------------------- 1 | // https://practice.geeksforgeeks.org/problems/count-distinct-pairs-with-difference-k1233/1/?page=1&difficulty[]=0&category[]=Map&sortBy=submissions 2 | // Difficulty : Easy Level 3 | // Accuracy: 24.76% 4 | 5 | #include 6 | using namespace std; 7 | class Solution{ 8 | public: 9 | int TotalPairs(vectornums, int k){ 10 | // Code here 11 | int n = nums.size(); 12 | //map, int> mp; 13 | //int count = 0; 14 | // for (int i = 0; i < n; i++) { 15 | // for (int j = i + 1; j < n; j++) { 16 | // if ((abs(nums[j] - nums[i])) == k) { 17 | // if(mp.find({nums[i], nums[j]}) == mp.end() && mp.find({nums[j], nums[i]}) == mp.end()){ 18 | // count++; 19 | // mp[{nums[i], nums[j]}] = 1; 20 | // mp[{nums[j], nums[i]}] = 1; 21 | // ;} 22 | // } 23 | // } 24 | // } 25 | // return count 26 | //TLE ON TEST CASE 136/142 27 | 28 | map mp; 29 | map, int> done; 30 | int count = 0; 31 | for(int i=0;i1){ 37 | if(!done.count({nums[i], nums[i]+k}) && (!done.count({nums[i]+k, nums[i]}))){ 38 | count++; 39 | done[{nums[i], nums[i]+k}]=1; 40 | done[{nums[i]+k, nums[i]}]=1; 41 | } 42 | } 43 | } 44 | else{ 45 | if(mp.count(nums[i]+k)){ 46 | if(!done.count({nums[i], nums[i]+k}) && (!done.count({nums[i]+k, nums[i]}))){ 47 | count++; 48 | done[{nums[i], nums[i]+k}]=1; 49 | done[{nums[i]+k, nums[i]}]=1; 50 | } 51 | } 52 | if(mp.count(nums[i]-k)){ 53 | if(!done.count({nums[i], nums[i]-k}) && (!done.count({nums[i]-k, nums[i]}))){ 54 | count++; 55 | done[{nums[i], nums[i]-k}]=1; 56 | done[{nums[i]-k, nums[i]}]=1; 57 | } 58 | } 59 | } 60 | } 61 | return count; 62 | // TLE ON TEST CASE 140/142 63 | 64 | } 65 | 66 | }; 67 | 68 | // { Driver Code Starts. 69 | int main(){ 70 | int tc; 71 | cin >> tc; 72 | while(tc--){ 73 | int n, k; 74 | cin >> n >> k; 75 | vectornums(n); 76 | for(int i = 0; i < n; i++) 77 | cin >> nums[i]; 78 | Solution ob; 79 | int ans = ob.TotalPairs(nums, k); 80 | cout << ans <<"\n"; 81 | } 82 | return 0; 83 | } // } Driver Code Ends -------------------------------------------------------------------------------- /C++/KnightTourProblem.cpp: -------------------------------------------------------------------------------- 1 | // C++ program for Knight Tour problem 2 | #include 3 | using namespace std; 4 | 5 | #define N 8 6 | 7 | int solveKTUtil(int x, int y, int movei, int sol[N][N], 8 | int xMove[], int yMove[]); 9 | 10 | /* A utility function to check if i,j are 11 | valid indexes for N*N chessboard */ 12 | int isSafe(int x, int y, int sol[N][N]) 13 | { 14 | return (x >= 0 && x < N && y >= 0 && y < N 15 | && sol[x][y] == -1); 16 | } 17 | 18 | /* A utility function to print 19 | solution matrix sol[N][N] */ 20 | void printSolution(int sol[N][N]) 21 | { 22 | for (int x = 0; x < N; x++) { 23 | for (int y = 0; y < N; y++) 24 | cout << " " << setw(2) << sol[x][y] << " "; 25 | cout << endl; 26 | } 27 | } 28 | 29 | /* This function solves the Knight Tour problem using 30 | Backtracking. This function mainly uses solveKTUtil() 31 | to solve the problem. It returns false if no complete 32 | tour is possible, otherwise return true and prints the 33 | tour. 34 | Please note that there may be more than one solutions, 35 | this function prints one of the feasible solutions. */ 36 | int solveKT() 37 | { 38 | int sol[N][N]; 39 | 40 | /* Initialization of solution matrix */ 41 | for (int x = 0; x < N; x++) 42 | for (int y = 0; y < N; y++) 43 | sol[x][y] = -1; 44 | 45 | /* xMove[] and yMove[] define next move of Knight. 46 | xMove[] is for next value of x coordinate 47 | yMove[] is for next value of y coordinate */ 48 | int xMove[8] = { 2, 1, -1, -2, -2, -1, 1, 2 }; 49 | int yMove[8] = { 1, 2, 2, 1, -1, -2, -2, -1 }; 50 | 51 | // Since the Knight is initially at the first block 52 | sol[0][0] = 0; 53 | 54 | /* Start from 0,0 and explore all tours using 55 | solveKTUtil() */ 56 | if (solveKTUtil(0, 0, 1, sol, xMove, yMove) == 0) { 57 | cout << "Solution does not exist"; 58 | return 0; 59 | } 60 | else 61 | printSolution(sol); 62 | 63 | return 1; 64 | } 65 | 66 | /* A recursive utility function to solve Knight Tour 67 | problem */ 68 | int solveKTUtil(int x, int y, int movei, int sol[N][N], 69 | int xMove[8], int yMove[8]) 70 | { 71 | int k, next_x, next_y; 72 | if (movei == N * N) 73 | return 1; 74 | 75 | /* Try all next moves from 76 | the current coordinate x, y */ 77 | for (k = 0; k < 8; k++) { 78 | next_x = x + xMove[k]; 79 | next_y = y + yMove[k]; 80 | if (isSafe(next_x, next_y, sol)) { 81 | sol[next_x][next_y] = movei; 82 | if (solveKTUtil(next_x, next_y, movei + 1, sol, 83 | xMove, yMove) 84 | == 1) 85 | return 1; 86 | else 87 | 88 | // backtracking 89 | sol[next_x][next_y] = -1; 90 | } 91 | } 92 | return 0; 93 | } 94 | 95 | // Driver Code 96 | int main() 97 | { 98 | // Function Call 99 | solveKT(); 100 | return 0; 101 | } 102 | 103 | // This code is contributed by ShubhamCoder 104 | -------------------------------------------------------------------------------- /C++/mergelinkedlist.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Name : Rounak Ghosh 3 | Username : Rounak-Ghosh 4 | About : 4th year undergrad student at GCETTB 5 | */ 6 | 7 | #include 8 | using namespace std; 9 | 10 | class Node 11 | { 12 | public: 13 | int data; 14 | Node* next; 15 | }; 16 | 17 | void printList(Node* n) 18 | { 19 | while (n != NULL) 20 | { 21 | cout << n->data << " "; 22 | n = n->next; 23 | } 24 | cout << endl; 25 | } 26 | 27 | void insertAtEnd(Node* &head, int val) 28 | { 29 | Node* n = new Node(); 30 | n -> data = val; 31 | if(head == NULL) 32 | { 33 | head = n; 34 | return; 35 | } 36 | Node* last = head; 37 | while(last -> next != NULL) 38 | last = last->next; 39 | last -> next = n; 40 | } 41 | 42 | Node* mergeList(Node* &head1, Node* &head2) 43 | { 44 | Node* p1 = head1; 45 | Node* p2 = head2; 46 | Node* dummyNode = new Node(); 47 | Node* p3 = dummyNode; 48 | 49 | while(p1 != NULL && p2 != NULL) 50 | { 51 | if(p1->data < p2->data) 52 | { 53 | p3->next = p1; 54 | p1 = p1->next; 55 | } 56 | else 57 | { 58 | p3->next = p2; 59 | p2 = p2->next; 60 | } 61 | p3 = p3->next; 62 | } 63 | 64 | while(p1!=NULL) 65 | { 66 | p3->next = p1; 67 | p1 = p1->next; 68 | p3 = p3->next; 69 | } 70 | 71 | while(p2!=NULL) 72 | { 73 | p3->next = p2; 74 | p2 = p2->next; 75 | p3 = p3->next; 76 | } 77 | 78 | return dummyNode->next; 79 | } 80 | 81 | Node* mergeRecursive(Node* &head1, Node* &head2) 82 | { 83 | if(head1 == NULL) 84 | return head2; 85 | if(head2 == NULL) 86 | return head1; 87 | 88 | Node* result; 89 | if(head1->data < head2->data) 90 | { 91 | result = head1; 92 | result->next = mergeRecursive(head1->next, head2); 93 | } 94 | else 95 | { 96 | result = head2; 97 | result->next = mergeRecursive(head1, head2->next); 98 | } 99 | return result; 100 | } 101 | 102 | int main() 103 | { 104 | Node* head1 = new Node(); 105 | Node* head2 = new Node(); 106 | 107 | head1 = NULL; 108 | head2 = NULL; 109 | 110 | insertAtEnd(head1, 1); 111 | insertAtEnd(head1, 4); 112 | insertAtEnd(head1, 5); 113 | insertAtEnd(head1, 7); 114 | printList(head1); 115 | 116 | insertAtEnd(head2, 2); 117 | insertAtEnd(head2, 3); 118 | insertAtEnd(head2, 6); 119 | printList(head2); 120 | 121 | //Node* newhead = mergeList(head1, head2); 122 | //printList(newhead); 123 | 124 | Node* newhd = mergeRecursive(head1, head2); 125 | printList(newhd); 126 | 127 | return 0; 128 | } -------------------------------------------------------------------------------- /C++/FibonacciSearch.cpp: -------------------------------------------------------------------------------- 1 | // C++ program of th above approach 2 | #include 3 | 4 | using namespace std; 5 | 6 | 7 | // Utility function to find minimum of two elements 8 | 9 | int min(int x, int y) { return (x <= y) ? x : y; } 10 | 11 | 12 | /* Returns index of x if present, else returns -1 */ 13 | 14 | int fibMonaccianSearch(int arr[], int x, int n) 15 | { 16 | 17 | /* Initialize fibonacci numbers */ 18 | 19 | int fibMMm2 = 0; // (m-2)'th Fibonacci No. 20 | 21 | int fibMMm1 = 1; // (m-1)'th Fibonacci No. 22 | 23 | int fibM = fibMMm2 + fibMMm1; // m'th Fibonacci 24 | 25 | 26 | 27 | /* fibM is going to store the smallest Fibonacci 28 | 29 | Number greater than or equal to n */ 30 | 31 | while (fibM < n) { 32 | 33 | fibMMm2 = fibMMm1; 34 | 35 | fibMMm1 = fibM; 36 | 37 | fibM = fibMMm2 + fibMMm1; 38 | 39 | } 40 | 41 | 42 | 43 | // Marks the eliminated range from front 44 | 45 | int offset = -1; 46 | 47 | 48 | 49 | /* while there are elements to be inspected. Note that 50 | 51 | we compare arr[fibMm2] with x. When fibM becomes 1, 52 | 53 | fibMm2 becomes 0 */ 54 | 55 | while (fibM > 1) { 56 | 57 | // Check if fibMm2 is a valid location 58 | 59 | int i = min(offset + fibMMm2, n - 1); 60 | 61 | 62 | 63 | /* If x is greater than the value at index fibMm2, 64 | 65 | cut the subarray array from offset to i */ 66 | 67 | if (arr[i] < x) { 68 | 69 | fibM = fibMMm1; 70 | 71 | fibMMm1 = fibMMm2; 72 | 73 | fibMMm2 = fibM - fibMMm1; 74 | 75 | offset = i; 76 | 77 | } 78 | 79 | 80 | 81 | /* If x is greater than the value at index fibMm2, 82 | 83 | cut the subarray after i+1 */ 84 | 85 | else if (arr[i] > x) { 86 | 87 | fibM = fibMMm2; 88 | 89 | fibMMm1 = fibMMm1 - fibMMm2; 90 | 91 | fibMMm2 = fibM - fibMMm1; 92 | 93 | } 94 | 95 | 96 | 97 | /* element found. return index */ 98 | 99 | else 100 | 101 | return i; 102 | 103 | } 104 | 105 | 106 | 107 | /* comparing the last element with x */ 108 | 109 | if (fibMMm1 && arr[offset + 1] == x) 110 | 111 | return offset + 1; 112 | 113 | 114 | 115 | /*element not found. return -1 */ 116 | 117 | return -1; 118 | } 119 | 120 | 121 | // Driver Code 122 | 123 | int main() 124 | { 125 | 126 | int arr[] 127 | 128 | = { 10, 22, 35, 40, 45, 50, 80, 82, 85, 90, 100,235}; 129 | 130 | int n = sizeof(arr) / sizeof(arr[0]); 131 | 132 | int x = 235; 133 | 134 | int ind = fibMonaccianSearch(arr, x, n); 135 | 136 | if(ind>=0) 137 | 138 | cout << "Found at index: " << ind; 139 | 140 | else 141 | 142 | cout << x << " isn't present in the array"; 143 | 144 | 145 | 146 | return 0; 147 | } 148 | 149 | 150 | -------------------------------------------------------------------------------- /C++/IntervalTree.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | struct Interval 5 | { 6 | int low, high; 7 | }; 8 | 9 | // node in Interval Search Tree 10 | struct ITNode 11 | { 12 | Interval *i; 13 | int max; 14 | ITNode *left, *right; 15 | }; 16 | 17 | // function to create a new Interval Search Tree Node 18 | ITNode * newNode(Interval i) 19 | { 20 | ITNode *temp = new ITNode; 21 | temp->i = new Interval(i); 22 | temp->max = i.high; 23 | temp->left = temp->right = NULL; 24 | return temp; 25 | }; 26 | 27 | // function to insert a new Interval Search Tree Node 28 | // This is similar to BST Insert. Here the low value of interval 29 | // is used to maintain BST property 30 | ITNode *insert(ITNode *root, Interval i) 31 | { 32 | // Base case: Tree is empty, new node becomes root 33 | if (root == NULL) 34 | return newNode(i); 35 | 36 | // Get low value of interval at root 37 | int l = root->i->low; 38 | 39 | // If root's low value is smaller, then new interval goes to 40 | // left subtree 41 | if (i.low < l) 42 | root->left = insert(root->left, i); 43 | 44 | // Else, new node goes to right subtree. 45 | else 46 | root->right = insert(root->right, i); 47 | 48 | // Update the max value of this ancestor if needed 49 | if (root->max < i.high) 50 | root->max = i.high; 51 | 52 | return root; 53 | } 54 | 55 | // function to check if given two intervals overlap 56 | bool doOVerlap(Interval i1, Interval i2) 57 | { 58 | if (i1.low <= i2.high && i2.low <= i1.high) 59 | return true; 60 | return false; 61 | } 62 | 63 | // function to search a given interval i in a given Interval tree 64 | Interval *overlapSearch(ITNode *root, Interval i) 65 | { 66 | // Base Case, tree is empty 67 | if (root == NULL) return NULL; 68 | 69 | // If given interval overlaps with root 70 | if (doOVerlap(*(root->i), i)) 71 | return root->i; 72 | 73 | // If left child of root is present and max of left child is 74 | // greater than or equal to given interval, then i may 75 | // overlap with an interval is left subtree 76 | if (root->left != NULL && root->left->max >= i.low) 77 | return overlapSearch(root->left, i); 78 | 79 | // Else interval can only overlap with right subtree 80 | return overlapSearch(root->right, i); 81 | } 82 | 83 | void inorder(ITNode *root) 84 | { 85 | if (root == NULL) return; 86 | 87 | inorder(root->left); 88 | 89 | cout << "[" << root->i->low << ", " << root->i->high << "]" 90 | << " max = " << root->max << endl; 91 | 92 | inorder(root->right); 93 | } 94 | 95 | // Driver program to test above functions 96 | int main() 97 | { 98 | // Let us create interval tree shown in above figure 99 | Interval ints[] = {{15, 20}, {10, 30}, {17, 19}, 100 | {5, 20}, {12, 15}, {30, 40} 101 | }; 102 | int n = sizeof(ints)/sizeof(ints[0]); 103 | ITNode *root = NULL; 104 | for (int i = 0; i < n; i++) 105 | root = insert(root, ints[i]); 106 | 107 | cout << "Inorder traversal of constructed Interval Tree is\n"; 108 | inorder(root); 109 | 110 | Interval x = {6, 7}; 111 | 112 | cout << "\nSearching for interval [" << x.low << "," << x.high << "]"; 113 | Interval *res = overlapSearch(root, x); 114 | if (res == NULL) 115 | cout << "\nNo Overlapping Interval"; 116 | else 117 | cout << "\nOverlaps with [" << res->low << ", " << res->high << "]"; 118 | return 0; 119 | } 120 | -------------------------------------------------------------------------------- /C++/EERTREEimplementation.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | using namespace std; 6 | struct Node 7 | { 8 | int s, e; 9 | int length; 10 | int b1; 11 | Node *suff; 12 | vector weights; 13 | 14 | Node() 15 | { 16 | s = e = length = -1; 17 | suff = nullptr; 18 | weights.assign(26, nullptr); 19 | } 20 | }; 21 | 22 | class EerTree 23 | { 24 | private: 25 | Node *root1; 26 | int b2; 27 | Node *root2; 28 | Node *current; 29 | 30 | public: 31 | EerTree() 32 | { 33 | root1 = new Node(); 34 | root1->length = -1; 35 | root1->suff = root1; 36 | 37 | root2 = new Node(); 38 | root2->length = 0; 39 | root2->suff = root1; 40 | current = root2; 41 | } 42 | 43 | int insert(string &s, int position) 44 | { 45 | Node *curr = current; 46 | int weight = s[position] - 'a'; 47 | 48 | while (true) 49 | { 50 | // loop is guranteed to break at root1 51 | if (position - 1 - curr->length >= 0 && s[position - 1 - curr->length] == s[position]) 52 | { 53 | break; 54 | } 55 | curr = curr->suff; 56 | } 57 | 58 | Node *temp = new Node(); 59 | temp->length = curr->length + 2; 60 | temp->e = position; 61 | temp->s = position - temp->length + 1; 62 | curr->weights[weight] = temp; 63 | 64 | if (temp->length == 1) 65 | { 66 | // if cur is root1 67 | temp->suff = root2; 68 | current = temp; 69 | return 0; 70 | } 71 | 72 | // find the suffix node 73 | while (true) 74 | { 75 | curr = curr->suff; 76 | if ((position - 1 - curr->length) >= 0 && s[position - 1 - curr->length] == s[position]) 77 | { 78 | temp->suff = curr->weights[weight]; 79 | break; 80 | } 81 | } 82 | current = temp; 83 | 84 | return 0; 85 | } 86 | 87 | void print(string s, Node *node) 88 | { 89 | if (node != root1 && node != root2) 90 | { 91 | for (int i = node->s; i <= node->e; ++i) 92 | { 93 | cout << s[i]; 94 | } 95 | cout << '\n'; 96 | } 97 | //int weight=s[position]-'a'; 98 | for (int i = 0; i < 26; ++i) 99 | { 100 | if ((node->weights[i]) != nullptr) 101 | { 102 | print(s, node->weights[i]); 103 | } 104 | } 105 | } 106 | 107 | void printAll(string &s) 108 | { 109 | print(s, root1); 110 | print(s, root2); 111 | } 112 | }; 113 | 114 | int main() 115 | { 116 | cout << "Enter a string to find its palindromic substrings: "; 117 | string s; 118 | cin >> s; 119 | time_t start, end, elapsed; 120 | start = clock(); 121 | EerTree tree; 122 | for (int i = 0; i < s.size(); ++i) 123 | tree.insert(s, i); 124 | cout << "insertion done\n"; 125 | cout << "Palindromic Substrings of given string are: \n"; 126 | tree.printAll(s); 127 | end = clock(); 128 | elapsed = end - start; 129 | cout << "The time taken is:" << elapsed << " microseconds" << endl; 130 | return 0; 131 | } -------------------------------------------------------------------------------- /C++/Longest Possible Route.cpp: -------------------------------------------------------------------------------- 1 | // C++ program to find Longest Possible Route in a 2 | // matrix with hurdles 3 | #include 4 | using namespace std; 5 | #define R 3 6 | #define C 10 7 | 8 | // A Pair to store status of a cell. found is set to 9 | // true of destination is reachable and value stores 10 | // distance of longest path 11 | struct Pair { 12 | // true if destination is found 13 | bool found; 14 | 15 | // stores cost of longest path from current cell to 16 | // destination cell 17 | int value; 18 | }; 19 | 20 | // Function to find Longest Possible Route in the 21 | // matrix with hurdles. If the destination is not reachable 22 | // the function returns false with cost INT_MAX. 23 | // (i, j) is source cell and (x, y) is destination cell. 24 | Pair findLongestPathUtil(int mat[R][C], int i, int j, int x, 25 | int y, bool visited[R][C]) 26 | { 27 | 28 | // if (i, j) itself is destination, return true 29 | if (i == x && j == y) { 30 | Pair p = { true, 0 }; 31 | return p; 32 | } 33 | 34 | // if not a valid cell, return false 35 | if (i < 0 || i >= R || j < 0 || j >= C || mat[i][j] == 0 36 | || visited[i][j]) { 37 | Pair p = { false, INT_MAX }; 38 | return p; 39 | } 40 | 41 | // include (i, j) in current path i.e. 42 | // set visited(i, j) to true 43 | visited[i][j] = true; 44 | 45 | // res stores longest path from current cell (i, j) to 46 | // destination cell (x, y) 47 | int res = INT_MIN; 48 | 49 | // go left from current cell 50 | Pair sol 51 | = findLongestPathUtil(mat, i, j - 1, x, y, visited); 52 | 53 | // if destination can be reached on going left from 54 | // current cell, update res 55 | if (sol.found) 56 | res = max(res, sol.value); 57 | 58 | // go right from current cell 59 | sol = findLongestPathUtil(mat, i, j + 1, x, y, visited); 60 | 61 | // if destination can be reached on going right from 62 | // current cell, update res 63 | if (sol.found) 64 | res = max(res, sol.value); 65 | 66 | // go up from current cell 67 | sol = findLongestPathUtil(mat, i - 1, j, x, y, visited); 68 | 69 | // if destination can be reached on going up from 70 | // current cell, update res 71 | if (sol.found) 72 | res = max(res, sol.value); 73 | 74 | // go down from current cell 75 | sol = findLongestPathUtil(mat, i + 1, j, x, y, visited); 76 | 77 | // if destination can be reached on going down from 78 | // current cell, update res 79 | if (sol.found) 80 | res = max(res, sol.value); 81 | 82 | // Backtrack 83 | visited[i][j] = false; 84 | 85 | // if destination can be reached from current cell, 86 | // return true 87 | if (res != INT_MIN) { 88 | Pair p = { true, 1 + res }; 89 | return p; 90 | } 91 | 92 | // if destination can't be reached from current cell, 93 | // return false 94 | else { 95 | Pair p = { false, INT_MAX }; 96 | return p; 97 | } 98 | } 99 | 100 | // A wrapper function over findLongestPathUtil() 101 | void findLongestPath(int mat[R][C], int i, int j, int x, 102 | int y) 103 | { 104 | // create a boolean matrix to store info about 105 | // cells already visited in current route 106 | bool visited[R][C]; 107 | 108 | // initialize visited to false 109 | memset(visited, false, sizeof visited); 110 | 111 | // find longest route from (i, j) to (x, y) and 112 | // print its maximum cost 113 | Pair p = findLongestPathUtil(mat, i, j, x, y, visited); 114 | if (p.found) 115 | cout << "Length of longest possible route is " 116 | << p.value; 117 | 118 | // If the destination is not reachable 119 | else 120 | cout << "Destination not reachable from given " 121 | "source"; 122 | } 123 | 124 | // Driver code 125 | int main() 126 | { 127 | // input matrix with hurdles shown with number 0 128 | int mat[R][C] = { { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 }, 129 | { 1, 1, 0, 1, 1, 0, 1, 1, 0, 1 }, 130 | { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 } }; 131 | 132 | // find longest path with source (0, 0) and 133 | // destination (1, 7) 134 | findLongestPath(mat, 0, 0, 1, 7); 135 | 136 | return 0; 137 | } 138 | -------------------------------------------------------------------------------- /C++/BtreeImplementation.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | struct BTreeNode{ 4 | int *data; 5 | BTreeNode **child_ptr; 6 | bool leaf; 7 | int n; 8 | }*root = NULL, *np = NULL, *x = NULL; 9 | 10 | BTreeNode * init(){ 11 | int i; 12 | np = new BTreeNode; 13 | np->data = new int[5]; 14 | np->child_ptr = new BTreeNode *[6]; 15 | np->leaf = true; 16 | np->n = 0; 17 | for (i = 0; i < 6; i++) 18 | np->child_ptr[i] = NULL; 19 | return np; 20 | } 21 | void searchOrTraverse(BTreeNode *p) 22 | { 23 | cout<n; i++){ 26 | if (p->leaf == false) 27 | searchOrTraverse(p->child_ptr[i]); 28 | cout << " " << p->data[i]; 29 | } 30 | if (p->leaf == false) 31 | searchOrTraverse(p->child_ptr[i]); 32 | cout< p[j]) { 39 | temp = p[i]; 40 | p[i] = p[j]; 41 | p[j] = temp; 42 | } 43 | } 44 | int childSplitOp(BTreeNode *x, int i){ 45 | int j, mid; 46 | BTreeNode *np1, *np3, *y; 47 | np3 = init(); 48 | np3->leaf = true; 49 | if (i == -1){ 50 | mid = x->data[2]; 51 | x->data[2] = 0; 52 | x->n--; 53 | np1 = init(); 54 | np1->leaf = false; 55 | x->leaf = true; 56 | for (j = 3; j < 5; j++){ 57 | np3->data[j - 3] = x->data[j]; 58 | np3->child_ptr[j - 3] = x->child_ptr[j]; 59 | np3->n++; 60 | x->data[j] = 0; 61 | x->n--; 62 | } 63 | for (j = 0; j < 6; j++) 64 | x->child_ptr[j] = NULL; 65 | np1->data[0] = mid; 66 | np1->child_ptr[np1->n] = x; 67 | np1->child_ptr[np1->n + 1] = np3; 68 | np1->n++; 69 | root = np1; 70 | } 71 | else{ 72 | y = x->child_ptr[i]; 73 | mid = y->data[2]; 74 | y->data[2] = 0; 75 | y->n--; 76 | for (j = 3; j < 5; j++){ 77 | np3->data[j - 3] = y->data[j]; 78 | np3->n++; 79 | y->data[j] = 0; 80 | y->n--; 81 | } 82 | x->child_ptr[i + 1] = y; 83 | x->child_ptr[i + 1] = np3; 84 | } 85 | return mid; 86 | } 87 | void insertionOp(int a){ 88 | int i, temp; 89 | x = root; 90 | if (x == NULL) { 91 | root = init(); 92 | x = root; 93 | } 94 | else{ 95 | if (x->leaf == true && x->n == 5) { 96 | temp = childSplitOp(x, -1); 97 | x = root; 98 | for (i = 0; i < (x->n); i++){ 99 | if ((a > x->data[i]) && (a < x->data[i + 1])) { 100 | i++; 101 | break; 102 | } 103 | else if (a < x->data[0]) 104 | break; 105 | else 106 | continue; 107 | } 108 | x = x->child_ptr[i]; 109 | } 110 | else{ 111 | while (x->leaf == false) { 112 | for (i = 0; i < (x->n); i++){ 113 | if ((a > x->data[i]) && (a < x->data[i + 1])) { 114 | i++; 115 | break; 116 | } 117 | else if (a < x->data[0]) 118 | break; 119 | else 120 | continue; 121 | } 122 | if ((x->child_ptr[i])->n == 5) { 123 | temp = childSplitOp(x, i); 124 | x->data[x->n] = temp; 125 | x->n++; 126 | continue; 127 | } 128 | else 129 | x = x->child_ptr[i]; 130 | } 131 | } 132 | } 133 | x->data[x->n] = a; 134 | sort(x->data, x->n); 135 | x->n++; 136 | } 137 | int main(){ 138 | int i, n, t; 139 | cout<<"Enter the number elements for insertion operation "; 140 | cin>>n; 141 | cout<<"Enter the elements: "; 142 | for(i = 0; i < n; i++){ 143 | cin>>t; 144 | insertionOp(t); 145 | } 146 | cout<<"Traversing the constructed tree\n"; 147 | searchOrTraverse(root); 148 | getch(); 149 | } 150 | -------------------------------------------------------------------------------- /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 | subhamtheone@gmail.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 | -------------------------------------------------------------------------------- /Doctor Appointment system.cc: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | 6 | using namespace std; 7 | 8 | int bookAppointment() 9 | { 10 | system("cls"); 11 | 12 | cout<<"\n ----- Book Your Appointment ---- \n"; 13 | cout<<"\n ----- Availbale slots ---- \n"; 14 | 15 | //check if record already exist.. 16 | ifstream read; 17 | read.open("appointment.dat"); 18 | 19 | int hoursbook = 8; 20 | 21 | int arr[13] = {0,0,0,0,0,0,0,0,0,0,0,0,0}; 22 | int recordFound =0; 23 | 24 | if(read) 25 | { 26 | string line; 27 | char key = 'A'; 28 | int i = 9; 29 | 30 | while(getline(read, line)) { 31 | char temp = line[0]; 32 | int index = (temp - 65); 33 | arr[index]=1; 34 | recordFound = 1; 35 | } 36 | if(recordFound == 1) 37 | { 38 | cout<<"\n Appointment Summary by hours:"; 39 | char key = 'A'; 40 | int hours = 9; 41 | for(int i = 0; i<=12; i++) 42 | { 43 | if(i == 0){ 44 | if(arr[i] == 0) 45 | cout<<"\n "< 0"< 0"<"<"< 0"< "<>choice; 81 | 82 | if( !(choice >= 'A' && choice <='Z')) 83 | { 84 | cout<"\n Error : Invalid Selection"; 85 | cout<<"\n Please selction correct value from menu A- Z"; 86 | cout<"\n Press any key to continue"; 87 | getchar();getchar(); 88 | system("cls"); 89 | bookAppointment(); 90 | } 91 | 92 | int index = (choice-65 ); 93 | int isBooked = 1; 94 | if(arr[index] == 0) 95 | isBooked = 0; 96 | 97 | if(isBooked ==1) 98 | { 99 | cout<<"\n Error : Appointment is already booked for this Hour"; 100 | cout<<"\n Please select different time !!"; 101 | cout<<"\n Press any key to continue!!"; 102 | getchar();getchar(); 103 | system("cls"); 104 | bookAppointment(); 105 | } 106 | 107 | string name; 108 | cout<<"\n Enter your first name:"; 109 | cin>>name; 110 | 111 | ofstream out; 112 | out.open("appointment.dat", ios::app); 113 | 114 | if(out){ 115 | out<"<"< 0"< "<>choice; 205 | 206 | switch(choice) 207 | { 208 | case 1: bookAppointment(); break; 209 | case 2: existingAppointment(); break; 210 | case 0: 211 | while(1) 212 | { 213 | system("cls"); 214 | cout<<"\n Are you sure, you want to exit? y | n \n"; 215 | char ex; 216 | cin>>ex; 217 | if(ex == 'y' || ex == 'Y') 218 | exit(0); 219 | else if(ex == 'n' || ex == 'N') 220 | { 221 | break; 222 | } 223 | else{ 224 | cout<<"\n Invalid choice !!!"; 225 | getchar(); 226 | } 227 | } break; 228 | 229 | default: cout<<"\n Invalid choice. Enter again "; 230 | getchar(); 231 | 232 | } 233 | 234 | } 235 | return 0; 236 | } 237 | -------------------------------------------------------------------------------- /main (1).cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | using namespace std; 8 | class Lib 9 | { 10 | public: 11 | char bookname[100],auname[50],sc[20],sc1[50]; 12 | int q,B,p; 13 | Lib() 14 | { 15 | strcpy(bookname,"NO Book Name"); 16 | strcpy(auname,"No Author Name"); 17 | strcpy(sc,"No Book ID"); 18 | strcpy(sc1,"No Book ID"); 19 | q=0; 20 | B=0; 21 | p=0; 22 | } 23 | void get(); 24 | void student(); 25 | void pass(); 26 | void librarian(); 27 | void password(); 28 | void getdata(); 29 | void show(int); 30 | void booklist(int); 31 | void modify(); 32 | void see(int); 33 | int branch(int); 34 | void issue(); 35 | void der(char[],int,int); 36 | void fine(int,int,int,int,int,int); 37 | }; 38 | void Lib::getdata() 39 | { 40 | int i; 41 | fflush(stdin); 42 | cout<<"\n\t\tEnter the details :-\n"; 43 | cout<<"\n\t\tEnter Book's Name : "; 44 | cin.getline(bookname,100); 45 | for(i=0;bookname[i]!='\0';i++) 46 | { 47 | if(bookname[i]>='a'&&bookname[i]<='z') 48 | bookname[i]-=32; 49 | } 50 | cout<<"\n\t\tEnter Author's Name : "; 51 | cin.getline(auname,50); 52 | cout<<"\n\t\tEnter Publication name : "; 53 | cin.getline(sc1,50); 54 | cout<<"\n\t\tEnter Book's ID : "; 55 | cin.getline(sc,20); 56 | cout<<"\n\t\tEnter Book's Price : "; 57 | cin>>p; 58 | cout<<"\n\t\tEnter Book's Quantity : "; 59 | cin>>q; 60 | } 61 | void Lib::show(int i) 62 | { 63 | cout<<"\n\t\tBook Name : "<>Please Choose one option :-\n"; 118 | cout<<"\n\t\t1.Modification In Current Books\n\n\t\t2.Add New Book\n\n\t\t3.Delete A Book\n\n\t\t4.Go back\n"; 119 | cout<<"\n\n\t\tEnter your choice : "; 120 | cin>>i; 121 | if(i==1) 122 | { 123 | system("cls"); 124 | b=branch(2); 125 | ifstream intf1("Booksdata.txt",ios::binary); 126 | if(!intf1) 127 | { 128 | cout<<"\n\t\tFile Not Found\n"; 129 | cout<<"\n\t\tPress any key to continue....."; 130 | getch(); 131 | system("cls"); 132 | librarian(); 133 | } 134 | intf1.close(); 135 | system("cls"); 136 | cout<<"\n\t\tPlease Choose One Option :-\n"; 137 | cout<<"\n\t\t1.Search By Book Name\n\n\t\t2.Search By Book's ID\n"; 138 | cout<<"\n\t\tEnter Your Choice : "; 139 | cin>>i; 140 | fflush(stdin); 141 | if(i==1) 142 | { 143 | system("cls"); 144 | cout<<"\n\t\tEnter Book Name : "; 145 | cin.getline(st1,100); 146 | system("cls"); 147 | fstream intf("Booksdata.txt",ios::in|ios::out|ios::ate|ios::binary); 148 | intf.seekg(0); 149 | intf.read((char*)this,sizeof(*this)); 150 | while(!intf.eof()) 151 | { 152 | for(i=0;b==B&&bookname[i]!='\0'&&st1[i]!='\0'&&(st1[i]==bookname[i]||st1[i]==bookname[i]+32);i++); 153 | if(bookname[i]=='\0'&&st1[i]=='\0') 154 | { 155 | cont++; 156 | getdata(); 157 | intf.seekp(intf.tellp()-sizeof(*this)); 158 | intf.write((char*)this,sizeof(*this)); 159 | break; 160 | } 161 | intf.read((char*)this,sizeof(*this)); 162 | } 163 | intf.close(); 164 | } 165 | else if(i==2) 166 | { 167 | cout<<"\n\t\tEnter Book's ID : "; 168 | cin.getline(st1,100); 169 | system("cls"); 170 | fstream intf("Booksdata.txt",ios::in|ios::out|ios::ate|ios::binary); 171 | intf.seekg(0); 172 | intf.read((char*)this,sizeof(*this)); 173 | while(!intf.eof()) 174 | { 175 | for(i=0;b==B&&sc[i]!='\0'&&st1[i]!='\0'&&st1[i]==sc[i];i++); 176 | if(sc[i]=='\0'&&st1[i]=='\0') 177 | { 178 | cont++; 179 | getdata(); 180 | intf.seekp(intf.tellp()-sizeof(*this)); 181 | intf.write((char*)this,sizeof(*this)); 182 | break; 183 | } 184 | intf.read((char*)this,sizeof(*this)); 185 | } 186 | 187 | intf.close(); 188 | } 189 | else 190 | { 191 | cout<<"\n\t\tIncorrect Input.....:(\n"; 192 | cout<<"\n\t\tPress any key to continue....."; 193 | getch(); 194 | system("cls"); 195 | modify(); 196 | } 197 | if(cont==0) 198 | { 199 | cout<<"\n\t\tBook Not Found.\n"; 200 | cout<<"\n\t\tPress any key to continue....."; 201 | getch(); 202 | system("cls"); 203 | modify(); 204 | } 205 | else 206 | cout<<"\n\t\tUpdate Successful.\n"; 207 | 208 | 209 | } 210 | else if(i==2) 211 | { 212 | system("cls"); 213 | B=branch(2); 214 | system("cls"); 215 | getdata(); 216 | ofstream outf("Booksdata.txt",ios::app|ios::binary); 217 | outf.write((char*)this,sizeof(*this)); 218 | outf.close(); 219 | cout<<"\n\t\tBook added Successfully.\n"; 220 | } 221 | else if(i==3) 222 | { 223 | system("cls"); 224 | b=branch(2); 225 | ifstream intf1("Booksdata.txt",ios::binary); 226 | if(!intf1) 227 | { 228 | cout<<"\n\t\tFile Not Found\n"; 229 | cout<<"\n\t\tPress any key to continue....."; 230 | getch(); 231 | intf1.close(); 232 | system("cls"); 233 | librarian(); 234 | } 235 | intf1.close(); 236 | system("cls"); 237 | cout<<"\n\t\tPlease Choose One Option for deletion:-\n"; 238 | cout<<"\n\t\t1.By Book Name\n\n\t\t2.By Book's ID\n"; 239 | cout<<"\n\t\tEnter Your Choice : "; 240 | cin>>i; 241 | fflush(stdin); 242 | if(i==1) 243 | { 244 | system("cls"); 245 | cout<<"\n\t\tEnter Book Name : "; 246 | cin.getline(st1,100); 247 | ofstream outf("temp.txt",ios::app|ios::binary); 248 | ifstream intf("Booksdata.txt",ios::binary); 249 | intf.read((char*)this,sizeof(*this)); 250 | while(!intf.eof()) 251 | { 252 | for(i=0;b==B&&bookname[i]!='\0'&&st1[i]!='\0'&&(st1[i]==bookname[i]||st1[i]==bookname[i]+32);i++); 253 | if(bookname[i]=='\0'&&st1[i]=='\0') 254 | { 255 | cont++; 256 | intf.read((char*)this,sizeof(*this)); 257 | 258 | } 259 | else 260 | { 261 | outf.write((char*)this,sizeof(*this)); 262 | intf.read((char*)this,sizeof(*this)); 263 | } 264 | } 265 | 266 | intf.close(); 267 | outf.close(); 268 | remove("Booksdata.txt"); 269 | rename("temp.txt","Booksdata.txt"); 270 | } 271 | else if(i==2) 272 | { 273 | cout<<"\n\t\tEnter Book's ID : "; 274 | cin.getline(st1,100); 275 | ofstream outf("temp.txt",ios::app|ios::binary); 276 | ifstream intf("Booksdata.txt",ios::binary); 277 | intf.read((char*)this,sizeof(*this)); 278 | while(!intf.eof()) 279 | { 280 | for(i=0;b==B&&sc[i]!='\0'&&st1[i]!='\0'&&st1[i]==sc[i];i++); 281 | if(sc[i]=='\0'&&st1[i]=='\0') 282 | { 283 | cont++; 284 | intf.read((char*)this,sizeof(*this)); 285 | } 286 | else 287 | { 288 | outf.write((char*)this,sizeof(*this)); 289 | intf.read((char*)this,sizeof(*this)); 290 | } 291 | } 292 | outf.close(); 293 | intf.close(); 294 | remove("Booksdata.txt"); 295 | rename("temp.txt","Booksdata.txt"); 296 | } 297 | else 298 | { 299 | cout<<"\n\t\tIncorrect Input.....:(\n"; 300 | cout<<"\n\t\tPress any key to continue....."; 301 | getch(); 302 | system("cls"); 303 | modify(); 304 | } 305 | if(cont==0) 306 | { 307 | cout<<"\n\t\tBook Not Found.\n"; 308 | cout<<"\n\t\tPress any key to continue....."; 309 | getch(); 310 | system("cls"); 311 | modify(); 312 | } 313 | else 314 | cout<<"\n\t\tDeletion Successful.\n"; 315 | 316 | } 317 | else if(i==4) 318 | { 319 | system("cls"); 320 | librarian(); 321 | } 322 | else 323 | { 324 | cout<<"\n\t\tWrong Input.\n"; 325 | cout<<"\n\t\tPress any key to continue....."; 326 | getch(); 327 | system("cls"); 328 | modify(); 329 | } 330 | cout<<"\n\t\tPress any key to continue....."; 331 | getch(); 332 | system("cls"); 333 | librarian(); 334 | 335 | } 336 | int Lib::branch(int x) 337 | { 338 | int i; 339 | cout<<"\n\t\t>>Please Choose one Branch :-\n"; 340 | cout<<"\n\t\t1.BIT\n\n\t\t2.EE\n\n\t\t3.EC\n\n\t\t4.CIVIL\n\n\t\t5.MECHANICAL\n\n\t\t6.1ST YEAR\n\n\t\t7.Go to menu\n"; 341 | cout<<"\n\t\tEnter youur choice : "; 342 | cin>>i; 343 | switch(i) 344 | { 345 | case 1: return 1; 346 | break; 347 | case 2: return 2; 348 | break; 349 | case 3: return 3; 350 | break; 351 | case 4: return 4; 352 | break; 353 | case 5: return 5; 354 | break; 355 | case 6: return 6; 356 | break; 357 | case 7: system("cls"); 358 | if(x==1) 359 | student(); 360 | else 361 | librarian(); 362 | default : cout<<"\n\t\tPlease enter correct option :("; 363 | getch(); 364 | system("cls"); 365 | branch(x); 366 | } 367 | } 368 | void Lib::see(int x) 369 | { 370 | int i,b,cont=0; 371 | char ch[100]; 372 | system("cls"); 373 | b=branch(x); 374 | ifstream intf("Booksdata.txt",ios::binary); 375 | if(!intf) 376 | { 377 | cout<<"\n\t\tFile Not Found.\n"; 378 | cout<<"\n\t\t->Press any key to continue....."; 379 | getch(); 380 | system("cls"); 381 | if(x==1) 382 | student(); 383 | else 384 | librarian(); 385 | } 386 | 387 | system("cls"); 388 | cout<<"\n\t\tPlease Choose one option :-\n"; 389 | cout<<"\n\t\t1.Search By Name\n\n\t\t2.Search By Book's ID\n"; 390 | cout<<"\n\t\tEnter Your Choice : "; 391 | cin>>i; 392 | fflush(stdin); 393 | intf.read((char*)this,sizeof(*this)); 394 | if(i==1) 395 | { 396 | cout<<"\n\t\tEnter Book's Name : "; 397 | cin.getline(ch,100); 398 | system("cls"); 399 | while(!intf.eof()) 400 | { 401 | for(i=0;b==B&&q!=0&&bookname[i]!='\0'&&ch[i]!='\0'&&(ch[i]==bookname[i]||ch[i]==bookname[i]+32);i++); 402 | if(bookname[i]=='\0'&&ch[i]=='\0') 403 | { 404 | cout<<"\n\t\tBook Found :-\n"; 405 | show(x); 406 | cont++; 407 | break; 408 | } 409 | intf.read((char*)this,sizeof(*this)); 410 | } 411 | } 412 | else if(i==2) 413 | { 414 | cout<<"\n\t\tEnter Book's ID : "; 415 | cin.getline(ch,100); 416 | system("cls"); 417 | while(!intf.eof()) 418 | { 419 | for(i=0;b==B&&q!=0&&sc[i]!='\0'&&ch[i]!='\0'&&ch[i]==sc[i];i++); 420 | if(sc[i]=='\0'&&ch[i]=='\0') 421 | { 422 | cout<<"\n\t\tBook Found :-\n"; 423 | show(x); 424 | cont++; 425 | break; 426 | } 427 | intf.read((char*)this,sizeof(*this)); 428 | } 429 | 430 | } 431 | else 432 | { 433 | cont++; 434 | cout<<"\n\t\tPlease enter correct option :("; 435 | getch(); 436 | system("cls"); 437 | see(x); 438 | } 439 | intf.close(); 440 | if(cont==0) 441 | cout<<"\n\t\tThis Book is not available :( \n"; 442 | 443 | cout<<"\n\t\tPress any key to continue....."; 444 | getch(); 445 | system("cls"); 446 | if(x==1) 447 | student(); 448 | else 449 | librarian(); 450 | 451 | 452 | } 453 | void Lib::issue() 454 | { 455 | char st[50],st1[20]; 456 | int b,i,j,d,m,y,dd,mm,yy,cont=0; 457 | system("cls"); 458 | cout<<"\n\t\t->Please Choose one option :-\n"; 459 | cout<<"\n\t\t1.Issue Book\n\n\t\t2.View Issued Book\n\n\t\t3.Search student who isuued books\n\n\t\t4.Reissue Book\n\n\t\t5.Return Book\n\n\t\t6.Go back to menu\n\n\t\tEnter Your Choice : "; 460 | cin>>i; 461 | fflush(stdin); 462 | if(i==1) 463 | { 464 | system("cls"); 465 | b=branch(2); 466 | system("cls"); 467 | fflush(stdin); 468 | cout<<"\n\t\t->Please Enter Details :-\n"; 469 | cout<<"\n\t\tEnter Book Name : "; 470 | cin.getline(bookname,100); 471 | cout<<"\n\t\tEnter Book's ID : "; 472 | cin.getline(sc,20); 473 | //strcpy(st,sc); 474 | der(sc,b,1); 475 | cout<<"\n\t\tEnter Student Name : "; 476 | cin.getline(auname,100); 477 | cout<<"\n\t\tEnter Student's ID : "; 478 | cin.getline(sc1,20); 479 | cout<<"\n\t\tEnter date : "; 480 | cin>>q>>B>>p; 481 | ofstream outf("student.txt",ios::binary|ios::app); 482 | outf.write((char*)this,sizeof(*this)); 483 | outf.close(); 484 | cout<<"\n\n\t\tIssue Successfully.\n"; 485 | } 486 | else if(i==2) 487 | { 488 | ifstream intf("student.txt",ios::binary); 489 | system("cls"); 490 | cout<<"\n\t\t->The Details are :-\n"; 491 | intf.read((char*)this,sizeof(*this)); 492 | i=0; 493 | while(!intf.eof()) 494 | { 495 | i++; 496 | cout<<"\n\t\t********** "<Please Enter Details :-\n"; 507 | cout<<"\n\n\t\tEnter Student Name : "; 508 | cin.getline(st,50); 509 | cout<<"\n\n\t\tEnter Student's ID : "; 510 | cin.getline(st1,20); 511 | system("cls"); 512 | ifstream intf("student.txt",ios::binary); 513 | intf.read((char*)this,sizeof(*this)); 514 | cont=0; 515 | while(!intf.eof()) 516 | { 517 | for(i=0;sc1[i]!='\0'&&st1[i]!='\0'&&st1[i]==sc1[i];i++); 518 | if(sc1[i]=='\0'&&st1[i]=='\0') 519 | { 520 | cont++; 521 | if(cont==1) 522 | { 523 | cout<<"\n\t\t->The Details are :-\n"; 524 | cout<<"\n\t\tStudent Name : "<Please Enter Details :-\n"; 544 | cout<<"\n\n\t\tEnter Student's ID : "; 545 | cin.getline(st,50); 546 | cout<<"\n\t\tEnter Book's ID : "; 547 | cin.getline(st1,20); 548 | fstream intf("student.txt",ios::in|ios::out|ios::ate|ios::binary); 549 | intf.seekg(0); 550 | intf.read((char*)this,sizeof(*this)); 551 | while(!intf.eof()) 552 | { 553 | for(i=0;sc[i]!='\0'&&st1[i]!='\0'&&st1[i]==sc[i];i++); 554 | for(j=0;sc1[j]!='\0'&&st[j]!='\0'&&st[j]==sc1[j];j++); 555 | if(sc[i]=='\0'&&sc1[j]=='\0'&&st[j]=='\0'&&st1[i]=='\0') 556 | { 557 | d=q; 558 | m=B; 559 | y=p; 560 | cout<<"\n\t\tEnter New Date : "; 561 | cin>>q>>B>>p; 562 | fine(d,m,y,q,B,p); //fn1 563 | intf.seekp(intf.tellp()-sizeof(*this)); //fn3 564 | intf.write((char*)this,sizeof(*this)); //fn5 565 | cout<<"\n\n\t\tReissue successfully."; //fn3 566 | break; 567 | } 568 | intf.read((char*)this,sizeof(*this)); 569 | } 570 | intf.close(); 571 | } 572 | else if(i==5) 573 | { 574 | system("cls"); 575 | b=branch(2); 576 | system("cls"); 577 | fflush(stdin); 578 | cout<<"\n\t\t->Please Enter Details :-\n"; 579 | cout<<"\n\t\tEnter Book's ID : "; 580 | cin.getline(st1,20); 581 | der(st1,b,2); 582 | cout<<"\n\n\t\tEnter Student's ID : "; 583 | cin.getline(st,20); 584 | cout<<"\n\t\tEnter Present date : "; 585 | cin>>d>>m>>y; 586 | ofstream outf("temp.txt",ios::app|ios::binary); 587 | ifstream intf("student.txt",ios::binary); 588 | intf.read((char*)this,sizeof(*this)); 589 | while(!intf.eof()) 590 | { 591 | for(i=0;sc[i]!='\0'&&st1[i]!='\0'&&st1[i]==sc[i];i++); 592 | for(j=0;sc1[j]!='\0'&&st[j]!='\0'&&st[j]==sc1[j];j++); 593 | if(sc[i]=='\0'&&sc1[j]=='\0'&&st[j]=='\0'&&st1[i]=='\0'&&cont==0) 594 | { 595 | cont++; 596 | intf.read((char*)this,sizeof(*this)); 597 | fine(q,B,p,d,m,y); 598 | cout<<"\n\t\tReturned successfully."; 599 | } 600 | else 601 | { 602 | outf.write((char*)this,sizeof(*this)); 603 | intf.read((char*)this,sizeof(*this)); 604 | } 605 | } 606 | 607 | intf.close(); 608 | outf.close(); 609 | getch(); 610 | remove("student.txt"); 611 | rename("temp.txt","student.txt"); 612 | } 613 | else if(i==6) 614 | { 615 | system("cls"); 616 | librarian(); 617 | } 618 | else 619 | cout<<"\n\t\tWrong Input.\n"; 620 | 621 | cout<<"\n\n\t\tPress any key to continue....."; 622 | getch(); 623 | system("cls"); 624 | librarian(); 625 | } 626 | void Lib::fine(int d,int m,int y,int dd,int mm,int yy) 627 | { 628 | long int n1,n2; 629 | int years,l,i; 630 | const int monthDays[12] = {31, 28, 31, 30, 31, 30,31, 31, 30, 31, 30, 31}; 631 | n1 = y*365 + d; 632 | for (i=0; i0) 650 | cout<<"\n\t\tThe Total Fine is : "<>Please Choose Any Option To login \n"; 694 | cout<<"\n\t\t1.Student\n\n\t\t2.Librarian\n\n\t\t3.Close Application\n"; 695 | cout<<"\n\t\tEnter your choice : "; 696 | cin>>i; 697 | if(i==1) 698 | { 699 | system("cls"); 700 | student(); 701 | } 702 | else if(i==2) 703 | pass(); 704 | 705 | else if(i==3) 706 | exit(0); 707 | else 708 | { 709 | cout<<"\n\t\tPlease enter correct option :("; 710 | getch(); 711 | system("CLS"); 712 | get(); 713 | } 714 | } 715 | void Lib::student() 716 | { 717 | int i; 718 | cout<<"\n\t************ WELCOME STUDENT ************\n"; 719 | cout<<"\n\t\t>>Please Choose One Option:\n"; 720 | cout<<"\n\t\t1.View BookList\n\n\t\t2.Search for a Book\n\n\t\t3.Go to main menu\n\n\t\t4.Close Application\n"; 721 | cout<<"\n\t\tEnter your choice : "; 722 | cin>>i; 723 | if(i==1) 724 | booklist(1); 725 | else if(i==2) 726 | see(1); 727 | else if(i==3) 728 | { 729 | system("cls"); 730 | get(); 731 | } 732 | else if(i==4) 733 | exit(0); 734 | else 735 | { 736 | cout<<"\n\t\tPlease enter correct option :("; 737 | getch(); 738 | system("cls"); 739 | student(); 740 | } 741 | } 742 | void Lib::pass() 743 | { 744 | int i=0; 745 | char ch,st[21],ch1[21]={"pass"}; 746 | cout<<"\n\t\tEnter Password : "; 747 | while(1) 748 | { 749 | ch=getch(); 750 | if(ch==13) 751 | { 752 | st[i]='\0'; 753 | break; 754 | } 755 | else if(ch==8&&i>0) 756 | { 757 | i--; 758 | cout<<"\b \b"; 759 | } 760 | else 761 | { 762 | cout<<"*"; 763 | st[i]=ch; 764 | i++; 765 | } 766 | } 767 | ifstream inf("password.txt"); 768 | inf>>ch1; 769 | inf.close(); 770 | for(i=0;st[i]==ch1[i]&&st[i]!='\0'&&ch1[i]!='\0';i++); 771 | if(st[i]=='\0'&&ch1[i]=='\0') 772 | { 773 | system("cls"); 774 | librarian(); 775 | } 776 | else 777 | { 778 | cout<<"\n\n\t\tWrong Password.\n\n\t\ttry again.....\n"; 779 | getch(); 780 | system("cls"); 781 | get(); 782 | } 783 | } 784 | void Lib::librarian() 785 | { 786 | int i; 787 | cout<<"\n\t************ WELCOME LIBRARIAN ************\n"; 788 | cout<<"\n\t\t>>Please Choose One Option:\n"; 789 | cout<<"\n\t\t1.View BookList\n\n\t\t2.Search for a Book\n\n\t\t3.Modify/Add Book\n\n\t\t4.Issue Book\n\n\t\t5.Go to main menu\n\n\t\t6.Change Password\n\n\t\t7.Close Application\n"; 790 | cout<<"\n\t\tEnter your choice : "; 791 | cin>>i; 792 | switch(i) 793 | { 794 | case 1:booklist(2); 795 | break; 796 | case 2:see(2); 797 | break; 798 | case 3:modify(); 799 | break; 800 | case 4:issue(); 801 | break; 802 | case 5:system("cls"); 803 | get(); 804 | break; 805 | case 6:password(); 806 | break; 807 | case 7:exit(0); 808 | default:cout<<"\n\t\tPlease enter correct option :("; 809 | getch(); 810 | system("cls"); 811 | librarian(); 812 | } 813 | } 814 | void Lib::password() 815 | { 816 | int i=0,j=0; 817 | char ch,st[21],ch1[21]={"pass"}; 818 | system("cls"); 819 | cout<<"\n\n\t\tEnter Old Password : "; 820 | while(1) 821 | { 822 | ch=getch(); 823 | if(ch==13) 824 | { 825 | st[i]='\0'; 826 | break; 827 | } 828 | else if(ch==8&&i>0) 829 | { 830 | i--; 831 | cout<<"\b \b"; 832 | } 833 | else 834 | { 835 | cout<<"*"; 836 | st[i]=ch; 837 | i++; 838 | } 839 | } 840 | ifstream intf("password.txt"); 841 | intf>>ch1; 842 | intf.close(); 843 | for(i=0;st[i]==ch1[i]&&st[i]!='\0'&&ch1[i]!='\0';i++); 844 | if(st[i]=='\0'&&ch1[i]=='\0') 845 | { 846 | system("cls"); 847 | cout<<"\n\t**The Password Should be less than 20 characters & don't use spaces**\n\n"; 848 | cout<<"\n\t\tEnter New Password : "; 849 | fflush(stdin); 850 | i=0; 851 | while(1) 852 | { 853 | j++; 854 | ch=getch(); 855 | if(ch==13) 856 | { 857 | for(i=0;st[i]!=' '&&st[i]!='\0';i++); 858 | if(j>20 || st[i]==' ') 859 | { 860 | cout<<"\n\n\t\tYou did't follow the instruction \n\n\t\tPress any key for try again....."; 861 | getch(); 862 | system("cls"); 863 | password(); 864 | librarian(); 865 | } 866 | st[i]='\0'; 867 | break; 868 | } 869 | else if(ch==8&&i>0) 870 | { 871 | i--; 872 | cout<<"\b \b"; 873 | } 874 | else 875 | { 876 | cout<<"*"; 877 | st[i]=ch; 878 | i++; 879 | } 880 | } 881 | ofstream outf("password.txt"); 882 | outf<>i; 895 | if(i==1) 896 | { 897 | system("cls"); 898 | password(); 899 | } 900 | else 901 | { 902 | system("cls"); 903 | librarian(); 904 | } 905 | } 906 | } 907 | int main() 908 | { 909 | Lib obj; 910 | obj.get(); 911 | getch(); 912 | return 0; 913 | } 914 | --------------------------------------------------------------------------------