Skip to content

Commit a40a6be

Browse files
authored
Merge branch 'master' into master
2 parents 497d7b0 + 6262e40 commit a40a6be

139 files changed

Lines changed: 9662 additions & 110 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

#hacktober2k19#cci

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
Thanks to Mukul And Rajat
2-
Thanks to Mukul And Rajat. Your video is still helpful in 2021
1+
Thanks to Mukul And Rajat.
2+
Thanks to Mukul And Rajat. Your video is still helpful in 2021.

01-Regression.ipynb

Lines changed: 163 additions & 0 deletions
Large diffs are not rendered by default.

1's&2'sCompliment.cpp

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
#include <iostream>
2+
#include<string>
3+
#include<cstdio>
4+
using namespace std;
5+
6+
int main()
7+
{
8+
int len=8;
9+
char bin[len],one[len],two[len];
10+
cout<<"Enter the Binary Number:";
11+
gets(bin);
12+
int flag =0;
13+
for(int i=0;i<len;i++)//one's compliment
14+
{
15+
if(bin[i]=='1')
16+
{
17+
one[i]='0';
18+
}
19+
else if(bin[i]=='0')
20+
{
21+
one[i]='1';
22+
}
23+
else
24+
{
25+
cout<<"Invalid Binary Digits";
26+
flag=1;
27+
return 0;
28+
}
29+
}
30+
int carry=1;
31+
for(int i=len-1;i>=0;i--)//two's compliment
32+
{
33+
if(one[i]=='1' && carry==1)
34+
{
35+
two[i]='0';
36+
}
37+
else if(one[i]=='0' && carry==1)
38+
{
39+
two[i]='1';
40+
carry=0;
41+
}
42+
else
43+
{
44+
two[i]=one[i];
45+
}
46+
}
47+
if(flag==0)
48+
{
49+
cout<<"Binary number is:"<<bin<<endl;
50+
cout<<"1's Compliment of the number is:"<<one<<endl;
51+
cout<<"2's Compliment of the number is:"<<two<<endl;
52+
}
53+
54+
return 0;
55+
}
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
You are given an integer array pref of size n. Find and return the array arr of size n that satisfies:
2+
3+
pref[i] = arr[0] ^ arr[1] ^ ... ^ arr[i].
4+
Note that ^ denotes the bitwise-xor operation.
5+
6+
It can be proven that the answer is unique.
7+
8+
9+
10+
Example 1:
11+
12+
Input: pref = [5,2,0,3,1]
13+
Output: [5,7,2,3,2]
14+
Explanation: From the array [5,7,2,3,2] we have the following:
15+
- pref[0] = 5.
16+
- pref[1] = 5 ^ 7 = 2.
17+
- pref[2] = 5 ^ 7 ^ 2 = 0.
18+
- pref[3] = 5 ^ 7 ^ 2 ^ 3 = 3.
19+
- pref[4] = 5 ^ 7 ^ 2 ^ 3 ^ 2 = 1.
20+
Example 2:
21+
22+
Input: pref = [13]
23+
Output: [13]
24+
Explanation: We have pref[0] = arr[0] = 13.
25+
26+
27+
Constraints:
28+
29+
1 <= pref.length <= 105
30+
0 <= pref[i] <= 106
31+
32+
Solution
33+
class Solution {
34+
public:
35+
vector<int> findArray(vector<int>& pref) {
36+
for(int i=pref.size()-1;i>0;i--){
37+
pref[i]=pref[i]^pref[i-1];
38+
}
39+
return pref;
40+
}
41+
};
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
30. Substring with Concatenation of All Words
2+
You are given a string s and an array of strings words. All the strings of words are of the same length.
3+
4+
A concatenated substring in s is a substring that contains all the strings of any permutation of words concatenated.
5+
6+
For example, if words = ["ab","cd","ef"], then "abcdef", "abefcd", "cdabef", "cdefab", "efabcd", and "efcdab" are all concatenated strings. "acdbef" is not a concatenated substring because it is not the concatenation of any permutation of words.
7+
Return the starting indices of all the concatenated substrings in s. You can return the answer in any order.
8+
9+
10+
11+
Example 1:
12+
13+
Input: s = "barfoothefoobarman", words = ["foo","bar"]
14+
Output: [0,9]
15+
Explanation: Since words.length == 2 and words[i].length == 3, the concatenated substring has to be of length 6.
16+
The substring starting at 0 is "barfoo". It is the concatenation of ["bar","foo"] which is a permutation of words.
17+
The substring starting at 9 is "foobar". It is the concatenation of ["foo","bar"] which is a permutation of words.
18+
The output order does not matter. Returning [9,0] is fine too.
19+
Example 2:
20+
21+
Input: s = "wordgoodgoodgoodbestword", words = ["word","good","best","word"]
22+
Output: []
23+
Explanation: Since words.length == 4 and words[i].length == 4, the concatenated substring has to be of length 16.
24+
There is no substring of length 16 is s that is equal to the concatenation of any permutation of words.
25+
We return an empty array.
26+
Example 3:
27+
28+
Input: s = "barfoofoobarthefoobarman", words = ["bar","foo","the"]
29+
Output: [6,9,12]
30+
Explanation: Since words.length == 3 and words[i].length == 3, the concatenated substring has to be of length 9.
31+
The substring starting at 6 is "foobarthe". It is the concatenation of ["foo","bar","the"] which is a permutation of words.
32+
The substring starting at 9 is "barthefoo". It is the concatenation of ["bar","the","foo"] which is a permutation of words.
33+
The substring starting at 12 is "thefoobar". It is the concatenation of ["the","foo","bar"] which is a permutation of words.
34+
35+
36+
37+
class Solution {
38+
public:
39+
vector<int> findSubstring(string s, vector<string>& words) {
40+
unordered_map<string, int> total;
41+
for(string s : words){
42+
total[s]+=1;
43+
}
44+
vector<int> ans;
45+
int wordSize = words[0].size(), noOfWords = words.size();
46+
for(int i = 0 ; i < s.size()-(wordSize*noOfWords)+1; i++){
47+
unordered_map <string,int>current;
48+
int j =0;
49+
for(; j < noOfWords; j++){
50+
string sub = s.substr(i+j*wordSize, wordSize);
51+
52+
current[sub]+=1;
53+
if(total.find(sub) == total.end())
54+
break;
55+
else if(current[sub] > total[sub])
56+
break; // this substring occurs more than the original no of occ.
57+
}
58+
59+
if(j == noOfWords) ans.push_back(i);
60+
61+
}
62+
63+
return ans;
64+
}
65+
};

Auto-File-Manager/Description.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
-> This program makes the any directory of the file manager looks cool by managing all the content of the specific directory. It store all content by creating seperate
2+
folder for images,media,document and also create Others folder to store the content which is not relevant to remaining 3 folders.
3+
-> It seperate the content by checking its extension.
4+
eg. if the extension of the file is .mp3 then that file will get store in media folder.
5+
-> The program takes any directory path as an input and then seperate the content according to their extension and store it in the given folder which is mentioned above.

Auto-File-Manager/README_Amaan.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# Auto_FileManager
2+
- The program makes the any directory of the file manager looks cool by managing all the content of the specific directory. It store all content by creating seperate
3+
folder for images,media,document and also create Others folder to store the content which is not relevant to remaining 3 folders.
4+
- It seperate the content by checking its extension.
5+
eg. if the extension of the file is .mp3 then that file will get store in media folder.
6+
- The program takes any directory path as an input and then seperate the content according to their extension and store it in the given folder which is mentioned above.
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
import os
2+
3+
directory = (input(r"Enter the path of the directory :"))
4+
5+
def makedirectory(folder):
6+
os.chdir(path=directory)
7+
if not os.path.exists(folder):
8+
os.makedirs(folder)
9+
10+
files = os.listdir(path=directory)
11+
makedirectory("Images")
12+
makedirectory("Docs")
13+
makedirectory("Media")
14+
makedirectory("Others")
15+
16+
imgext = ['.jpg','.png','.jpeg']
17+
imgs = [file for file in files if os.path.splitext(file)[1].lower() in imgext]
18+
# print(imgs)
19+
20+
docsext = ['.txt','.xml','.csv','.pdf','.docx','.doc','.xsl','.ppt']
21+
docs = [file for file in files if os.path.splitext(file)[1].lower() in docsext]
22+
# print(docs)
23+
24+
mediaext = ['.mp4','.mkv','.mp3','.flv','.avi','.wav']
25+
medias = [file for file in files if os.path.splitext(file)[1].lower() in mediaext]
26+
# print(medias)
27+
28+
others = []
29+
for file in files:
30+
ext = os.path.splitext(file)[1].lower()
31+
if (ext not in imgext) and (ext not in docsext) and (ext not in mediaext) and os.path.isfile(file):
32+
others.append(file)
33+
34+
# print(others)
35+
36+
37+
def move_to_folder(foldername,files):
38+
for file in files:
39+
os.replace(file,f"{foldername}/{file}")
40+
41+
move_to_folder("Media",medias)
42+
move_to_folder("Images",imgs)
43+
move_to_folder("Docs",docs)
44+
move_to_folder("Others",others)
45+
46+
47+

Book_Allocation_Problem.cpp

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
/*
2+
3+
Given an array ‘pages’ of integer numbers, where ‘pages[i]’ represents the number of pages in the ‘i-th’ book. There are ‘m’ number of students, and the task is to allocate all the books to their students.
4+
5+
Allocate books in a way such that:
6+
7+
1. Each student gets at least one book.
8+
9+
2. Each book should be allocated to a student.
10+
11+
3. Book allocation should be in a contiguous manner.
12+
13+
You have to allocate the books to ‘m’ students such that the maximum number of pages assigned to a student is minimum.
14+
15+
16+
*/
17+
#include <bits/stdc++.h>
18+
using namespace std;
19+
bool isPossible(int arr[], int n, int m, int mid)
20+
{
21+
int studentCount = 1;
22+
int pageSum = 0;
23+
for (int i = 0; i < n; i++)
24+
{
25+
if (pageSum + arr[i] <= mid)
26+
pageSum += arr[i];
27+
else
28+
{
29+
studentCount++;
30+
if (studentCount > m || arr[i] > mid)
31+
{
32+
return false;
33+
}
34+
pageSum = arr[i];
35+
}
36+
}
37+
return true;
38+
}
39+
int findPages(int arr[], int n, int m)
40+
{
41+
int sum = 0;
42+
for (size_t i = 0; i < n; i++)
43+
{
44+
sum += arr[i];
45+
}
46+
int s = 0, e = sum;
47+
int ans = -1;
48+
while (s <= e)
49+
{
50+
int mid = s + (e - s) / 2;
51+
if (isPossible(arr, n, m, mid))
52+
{
53+
ans = mid;
54+
e = mid - 1;
55+
}
56+
else
57+
{
58+
s = mid + 1;
59+
}
60+
}
61+
return ans;
62+
}
63+
int main()
64+
{
65+
int arr[] = {10, 20, 30, 40};
66+
int n = sizeof(arr) / sizeof(arr[0]);
67+
int m = 2;
68+
cout << findPages(arr, n, m);
69+
return 0;
70+
}

CodingClubIndia-master.zip

256 KB
Binary file not shown.

0 commit comments

Comments
 (0)