├── Black_T (1).png ├── contest_solutions ├── mini_contest-3 │ ├── Phantom_&_Divisors.cpp │ ├── Funny_Strings.cpp │ ├── Beatiful_triplets.cpp │ ├── Dp_Nahi_Aati_Vs_Pseudocodia.cpp │ └── Almost_sorted.cpp ├── mini_contest-1 │ ├── mini-max_sum.cpp │ ├── compare_the_triplets.cpp │ ├── electronics_shop.cpp │ ├── minimum_loss.cpp │ └── kangaroo.cpp └── mini_contest-2 │ ├── sock_merchant.cpp │ ├── angry_professor.cpp │ ├── jumping_on_the_clouds.cpp │ ├── organizing_containers_of_balls.cpp │ └── palindrome_index.cpp ├── Introduction to CP.md ├── schedule.md ├── README.md ├── Rules & General Information.md └── Resources.md /Black_T (1).png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PClub-Ahmedabad-University/CP101/HEAD/Black_T (1).png -------------------------------------------------------------------------------- /contest_solutions/mini_contest-3/Phantom_&_Divisors.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #define PI 3.14159265358979323846 4 | #define LIMIT 4294967296 5 | typedef long long ll; 6 | 7 | using namespace std; 8 | 9 | ll sq(ll n, ll m) 10 | { 11 | n %= m; 12 | return (n*n)%m; 13 | } 14 | 15 | int main() 16 | { 17 | ios_base::sync_with_stdio(false); 18 | cin.tie(NULL); 19 | 20 | int t=1; 21 | cin >> t; 22 | while(t--) 23 | { 24 | ll n,m,ans=0; 25 | cin >> n >> m; 26 | 27 | while(n) 28 | { 29 | ans = (ans + sq((n>>1) + (n&1), m)) % m; 30 | n >>= 1; 31 | } 32 | cout << ans << "\n"; 33 | } 34 | return 0; 35 | } 36 | -------------------------------------------------------------------------------- /contest_solutions/mini_contest-1/mini-max_sum.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #define PI 3.14159265358979323846 4 | #define LIMIT 4294967296 5 | typedef long long ll; 6 | 7 | using namespace std; 8 | 9 | int main() 10 | { 11 | ios_base::sync_with_stdio(false); 12 | cin.tie(NULL); 13 | 14 | int t=1; 15 | //cin >> t; 16 | while(t--) 17 | { 18 | int a[5]; 19 | for(int i=0; i<5; i++) 20 | cin >> a[i]; 21 | sort(a,a+5); 22 | ll al=0,bo=0; 23 | for(int i=0; i<4; i++) 24 | al += a[i]; 25 | for(int i=1;i<5;i++) 26 | bo += a[i]; 27 | 28 | cout << al << " " << bo; 29 | 30 | 31 | } 32 | return 0; 33 | } 34 | -------------------------------------------------------------------------------- /contest_solutions/mini_contest-2/sock_merchant.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #define PI 3.14159265358979323846 4 | #define LIMIT 4294967296 5 | typedef long long ll; 6 | 7 | using namespace std; 8 | 9 | int main() 10 | { 11 | ios_base::sync_with_stdio(false); 12 | cin.tie(NULL); 13 | 14 | int t=1; 15 | //cin >> t; 16 | while(t--) 17 | { 18 | int n; 19 | cin >> n; 20 | map m; 21 | 22 | while(n--) 23 | { 24 | int temp; 25 | cin >> temp; 26 | m[temp]++; 27 | } 28 | 29 | int ans=0; 30 | for(auto x:m) 31 | ans += x.second/2; 32 | 33 | cout << ans; 34 | } 35 | return 0; 36 | } 37 | -------------------------------------------------------------------------------- /contest_solutions/mini_contest-2/angry_professor.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #define PI 3.14159265358979323846 4 | #define LIMIT 4294967296 5 | typedef long long ll; 6 | 7 | using namespace std; 8 | 9 | int main() 10 | { 11 | ios_base::sync_with_stdio(false); 12 | cin.tie(NULL); 13 | 14 | int t=1; 15 | cin >> t; 16 | while(t--) 17 | { 18 | int n,k; 19 | cin >> n >> k; 20 | int a[n]; 21 | 22 | for(int i=0;i> a[i]; 24 | int cnt=0; 25 | for(int i=0;i= k) 29 | cout << "NO\n"; 30 | else 31 | cout << "YES\n"; 32 | } 33 | return 0; 34 | } 35 | -------------------------------------------------------------------------------- /contest_solutions/mini_contest-3/Funny_Strings.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #define PI 3.14159265358979323846 4 | #define LIMIT 4294967296 5 | typedef long long ll; 6 | 7 | using namespace std; 8 | 9 | int main() 10 | { 11 | ios_base::sync_with_stdio(false); 12 | cin.tie(NULL); 13 | 14 | int t=1; 15 | cin >> t; 16 | while(t--) 17 | { 18 | string s; 19 | cin >> s; 20 | string r = s; 21 | reverse(r.begin(),r.end()); 22 | 23 | for(int i=1;i 2 | #include 3 | #define PI 3.14159265358979323846 4 | #define LIMIT 4294967296 5 | typedef long long ll; 6 | 7 | using namespace std; 8 | 9 | int main() 10 | { 11 | ios_base::sync_with_stdio(false); 12 | cin.tie(NULL); 13 | 14 | int t=1; 15 | //cin >> t; 16 | while(t--) 17 | { 18 | int n,k; 19 | cin >> n >> k; 20 | int a[n]; 21 | for(int i=0;i> a[i]; 23 | 24 | int e=100; 25 | int ind = 0; 26 | 27 | do 28 | { 29 | e--; 30 | ind = (ind+k)%n; 31 | e -= a[ind]*2; 32 | } 33 | while(ind); 34 | 35 | cout << e; 36 | } 37 | return 0; 38 | } 39 | -------------------------------------------------------------------------------- /contest_solutions/mini_contest-1/compare_the_triplets.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #define PI 3.14159265358979323846 4 | #define LIMIT 4294967296 5 | typedef long long ll; 6 | 7 | using namespace std; 8 | 9 | int main() 10 | { 11 | ios_base::sync_with_stdio(false); 12 | cin.tie(NULL); 13 | 14 | int t=1; 15 | //cin >> t; 16 | while(t--) 17 | { 18 | int a[3],b[3]; 19 | for(int i=0; i<3; i++) 20 | cin >> a[i]; 21 | for(int i=0; i<3; i++) 22 | cin >> b[i]; 23 | 24 | int al=0,bo=0; 25 | for(int i=0; i<3; i++) 26 | { 27 | if(a[i] > b[i]) 28 | al++; 29 | else if(b[i] > a[i]) 30 | bo++; 31 | } 32 | 33 | cout << al << " " << bo; 34 | 35 | 36 | } 37 | return 0; 38 | } 39 | -------------------------------------------------------------------------------- /contest_solutions/mini_contest-3/Beatiful_triplets.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #define PI 3.14159265358979323846 4 | #define LIMIT 4294967296 5 | typedef long long ll; 6 | 7 | using namespace std; 8 | 9 | int main() 10 | { 11 | ios_base::sync_with_stdio(false); 12 | cin.tie(NULL); 13 | 14 | int t=1; 15 | //cin >> t; 16 | while(t--) 17 | { 18 | int n,d; 19 | cin >> n >> d; 20 | int a[n]; 21 | for(int i=0;i> a[i]; 23 | 24 | int ans=0; 25 | for(int i=0;i 2 | #include 3 | #define PI 3.14159265358979323846 4 | #define LIMIT 4294967296 5 | typedef long long ll; 6 | 7 | using namespace std; 8 | 9 | int main() 10 | { 11 | ios_base::sync_with_stdio(false); 12 | cin.tie(NULL); 13 | 14 | int t=1; 15 | //cin >> t; 16 | while(t--) 17 | { 18 | int b,k,u; 19 | cin >> b >> k >> u; 20 | 21 | int ke[k], us[u]; 22 | for(int i=0;i> ke[i]; 24 | for(int i=0;i> us[i]; 26 | 27 | int ans=-1; 28 | for(int i=0;i 2 | #include 3 | #define PI 3.14159265358979323846 4 | #define LIMIT 4294967296 5 | typedef long long ll; 6 | 7 | using namespace std; 8 | 9 | bool cmp(pair a,pair b) 10 | { 11 | return a.first < b.first; 12 | } 13 | 14 | int main() 15 | { 16 | ios_base::sync_with_stdio(false); 17 | cin.tie(NULL); 18 | 19 | int t=1; 20 | //cin >> t; 21 | while(t--) 22 | { 23 | int n; 24 | cin >> n; 25 | pair a[n]; 26 | for(int i=0;i> temp; 30 | a[i] = make_pair(temp,i); 31 | } 32 | 33 | sort(a,a+n,cmp); 34 | 35 | ll ans=10e16; 36 | for(int i=0;i 2 | #include 3 | #define PI 3.14159265358979323846 4 | #define LIMIT 4294967296 5 | typedef long long ll; 6 | 7 | using namespace std; 8 | 9 | int main() 10 | { 11 | ios_base::sync_with_stdio(false); 12 | cin.tie(NULL); 13 | 14 | int t=1; 15 | //cin >> t; 16 | while(t--) 17 | { 18 | int a[6]; 19 | for(int i=0;i<6;i++) 20 | cin >> a[i]; 21 | int sum = 0; 22 | for(int i=0;i<6;i++) 23 | sum += a[i]; 24 | 25 | if(sum&1) 26 | { 27 | cout << "NO"; 28 | return 0; 29 | } 30 | 31 | for(int i=0;i<=63;i++) 32 | { 33 | int temp = 0; 34 | for(int j=0;j<6;j++) 35 | if((i & (1< 2 | #include 3 | #define PI 3.14159265358979323846 4 | #define LIMIT 4294967296 5 | typedef long long ll; 6 | 7 | using namespace std; 8 | 9 | int main() 10 | { 11 | ios_base::sync_with_stdio(false); 12 | cin.tie(NULL); 13 | 14 | int t=1; 15 | //cin >> t; 16 | while(t--) 17 | { 18 | int x1,v1,x2,v2; 19 | cin >> x1 >> v1 >> x2 >> v2; 20 | 21 | if(x1 > x2) 22 | { 23 | swap(x1,x2); 24 | swap(v1,v2); 25 | } 26 | 27 | x2 -= x1; 28 | if(v1 < v2) 29 | { 30 | cout << "NO"; 31 | break; 32 | } 33 | else if(x2 == 0 && v1 == v2) 34 | { 35 | cout << "YES"; 36 | break; 37 | } 38 | 39 | if(v1 == v2) 40 | { 41 | cout << "NO"; 42 | break; 43 | } 44 | if(x2 % (v1-v2)) 45 | { 46 | cout << "NO"; 47 | } 48 | else 49 | cout << "YES"; 50 | } 51 | return 0; 52 | } 53 | -------------------------------------------------------------------------------- /contest_solutions/mini_contest-2/organizing_containers_of_balls.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #define PI 3.14159265358979323846 4 | #define LIMIT 4294967296 5 | typedef long long ll; 6 | 7 | using namespace std; 8 | 9 | int main() 10 | { 11 | ios_base::sync_with_stdio(false); 12 | cin.tie(NULL); 13 | 14 | int t=1; 15 | cin >> t; 16 | while(t--) 17 | { 18 | int n; 19 | cin >> n; 20 | int a[n][n]; 21 | for(int i=0;i> a[i][j]; 24 | 25 | ll row[n] = {0}, col[n] = {0}; 26 | for(int i=0; i 2 | #include 3 | #define PI 3.14159265358979323846 4 | #define LIMIT 4294967296 5 | typedef long long ll; 6 | 7 | using namespace std; 8 | 9 | int main() 10 | { 11 | ios_base::sync_with_stdio(false); 12 | cin.tie(NULL); 13 | 14 | int t=1; 15 | //cin >> t; 16 | while(t--) 17 | { 18 | int n; 19 | cin >> n; 20 | int a[n]; 21 | for(int i=0;i> a[i]; 23 | 24 | if(is_sorted(a,a+n)) 25 | { 26 | cout << "yes"; 27 | return 0; 28 | } 29 | 30 | int f=0,b=0; 31 | for(int i=0;i a[i+1]) 34 | { 35 | f=i; 36 | break; 37 | } 38 | } 39 | 40 | for(int i=n-1;i>=0;i--) 41 | { 42 | if(a[i] < a[i-1]) 43 | { 44 | b=i; 45 | break; 46 | } 47 | } 48 | swap(a[f],a[b]); 49 | 50 | if(is_sorted(a,a+n)) 51 | { 52 | cout << "yes\n" << "swap " << f+1 << " " << b+1; 53 | return 0; 54 | } 55 | 56 | reverse(a+f+1,a+b); 57 | 58 | if(is_sorted(a,a+n)) 59 | { 60 | cout << "yes\n" << "reverse " << f+1 << " " << b+1; 61 | return 0; 62 | } 63 | cout << "no"; 64 | } 65 | return 0; 66 | } 67 | -------------------------------------------------------------------------------- /schedule.md: -------------------------------------------------------------------------------- 1 | # SCHEDULE FOR CP101 2 | 3 | **Total days:** *15 days* 4 | 5 | **Total contests:** *3* 6 | 7 | **Total problems:** *>= 40* 8 | 9 | **Tentative Schedule for Resource sharing:** 10 | 11 | - New resources will be added after every _2-3_ days in the Resources section of the repository. 12 | 13 | - The resources are organised such that the reader can be comfortable solving tasks A & B of any programming contest after reading, learning and practicing these concepts. 14 | 15 | - The resources shared will cover topics such as (with tentative release dates): 16 | 17 | - Choosing a language - **26/08/2020** 18 | - Setting up IDE - **26/08/2020** 19 | - Getting familiar with your chosen language - **26/08/2020** 20 | - Kickstarting your journey in CP - **28/08/2020** 21 | - The Art of Debugging - **31/08/2020** 22 | - Understanding the Concept of Time and Space Complexity - **02/09/2020** 23 | - Basic Math and Data Structures with STL's - **05/09/2020** 24 | - Advanced Level Concepts for Competitive Programming - **07/09/2020** 25 | - Interesting blogs & video lectures - **Updated** 26 | 27 | - Important **Dates & Links** for Contests : 28 | - [Mini-contest #1](https://www.hackerrank.com/cp101-minicontest-1) : **3:00 PM IST, 30/08/2020** 29 | - [Mini-contest #2](https://www.hackerrank.com/cp101-mincontest-2) : **9:00 PM IST, 05/09/2020** 30 | - [Mini-contest #3](https://www.hackerrank.com/cp101-mini-contest3) : **9:00 PM IST, 09/09/2020** 31 | - [Final-contest](http://www.hackerrank.com/cp101-final-contest) : **3:00 PM IST, 12/09/2020** 32 | 33 | ### **_To be eligible for the certificate and completion of the course you must have atleast 1 AC i3/4 contests of this course_** 34 | 35 | **Note:** Keep checking the Schedule in the repository to keep track of any changes in the schedule or any important update. 36 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 |

CP101

2 | 3 |

4 | 5 |

6 | 7 | ## ABOUT THE COURSE 8 | 9 | Programming Club brings to you the **15-day** competitive programming course - CP101, for beginners where participants will get the opportunity to go through intensive resources and question sets which will enable them to kickstart their competitive programming journey and start participating in coding competitions online. 10 | 11 | The resources section of this course has been designed by identifying the common problems faced by beginners and by surveying the difficulties faced by our coding community. For instance, this document includes the guide to choose the best programming language for competitive programming, pointers to handle _runtime and compilation error, methods to avoid Memory Limit and Time Limit Exceeded_ while coding, the concepts/tricks needed to be able to solve at least one question in every contest, etc. 12 | 13 | Through this course, the participants will be **provided with handpicked resources** containing **blogs, video lectures and articles** available on the internet along with relevant _40-50 CP questions_. Additionally, mini-contests will be organised regularly for you to test the concepts learned. 14 | 15 | The participants who will complete the course will be provided a _certificate_ of completion from the club.. The criteria to be eligible for a certificate is to **solve at least 30 questions from the problem set and solve at least 1 question in each of the contests organised.** 16 | 17 | - Only Ahmedabad University students are allowed to participate. 18 | - **The course is specially designed for those who want to start competitive programming** and want to start solving at least one question in coding contests. 19 | - Every contest will be based upon the handouts & the resources provided before the date of contest and solutions of the contest will also be put in here. 20 | 21 | ### For further clarification 22 | + [Introduction to Competitve Programming](https://github.com/Programming-Club-Ahmedabad-University/CP101/blob/master/Introduction%20to%20CP.md) 23 | + [Rules & General Instructions](https://github.com/Programming-Club-Ahmedabad-University/CP101/blob/master/Rules%20%26%20General%20Information.md) 24 | + [Resources](https://github.com/Programming-Club-Ahmedabad-University/CP101/blob/master/Resources.md) 25 | + [Schedules](https://github.com/Programming-Club-Ahmedabad-University/CP101/blob/master/schedule.md) 26 | + [Solutions to contests held](https://github.com/Programming-Club-Ahmedabad-University/CP101/tree/master/contest_solutions) 27 | -------------------------------------------------------------------------------- /Rules & General Information.md: -------------------------------------------------------------------------------- 1 | 1. A new website has been developed for maintaining the Problem set and the Leaderboard throughout the event. **Participants have to register themselves using their Codeforces handle and Ahmedabad University email address**. 2 | 3 | - The Codeforces handle has to be recognised under ‘SEAS, Ahmedabad University’ organisation for the handle to be successfully registered on the website as this course is exclusively for Ahmedabad University students. 4 | - Kindly provide the correct Ahmedabad University email address. This address will be used to send completion certificates at the end. 5 | - It may take some time to reflect changes in the Leaderboard, so kindly be patient. 6 | - Link to the platform: https://pclub-cp.herokuapp.com/ 7 | 8 | 9 | 2. The leaderboard is rather a **record of progress** and not the **actual rank-list**. There won’t be any rankings provided to the participants. So take your time understanding and implementing the problems without any rush. 10 | 11 | 3. 2~3 contests will be organised throughout this course. Participants must take part and solve at least 1 question in each of them to be eligible for the certificate. Additionally, participants must solve at least 30 questions from the problem set to be eligible for the certificate. 12 | 13 | - *NOTE*: There might be some minor changes in the numbers above based on the response of participants. 14 | 15 | 4. This course is designed for cooperative learning. You can ask your doubts and discuss in Programming Club groups on WhatsApp or Discord and get your queries resolved. 16 | - WhatsApp group: https://chat.whatsapp.com/JFnE9GF85Tn8ZKXghbABF8 17 | - Discord server: https://discord.gg/Httn2HC 18 | 19 | 5. **Do not copy** solutions for the tasks from the problem set either from the internet or from fellow participants. Enough time is available for brainstorming. 20 | 6. Resources will be shared regularly by updating the “Resources” section under [Github-Programming Club-CP101](https://github.com/Programming-Club-Ahmedabad-University/CP101) throughout this course. 21 | - These resources are general purpose resources to help kick start competitive programming. They will contain blogs and videos on basic programming concepts such as ‘Time limits’ and ‘Memory limits’ in tasks, how to tackle ‘Compilation’ and ‘Runtime errors’, useful concepts to solve tasks A and B in contests, etc. 22 | - Furthermore, these resources will be valuable in learning new concepts as well as brushing up your knowledge with some timely quality practice problems. 23 | - And yes, _do star_ the repository if you like it! 24 | 25 | **Special Mention**: [Jeet Karia](https://github.com/JeetKaria06) & [Rahul Chocha](https://github.com/mrchocha), developers of the platform. 26 | -------------------------------------------------------------------------------- /contest_solutions/mini_contest-2/palindrome_index.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | #define MOD 1000000007 6 | #define test \ 7 | int t; \ 8 | cin >> t; \ 9 | while (t--) 10 | #define init(arr, val) memset(arr, val, sizeof(arr)) 11 | #define all(a) a.begin(), a.end() 12 | 13 | #define cins(s) \ 14 | string s; \ 15 | cin >> s; 16 | #define cini(i) \ 17 | int i; \ 18 | cin >> i; 19 | #define cinll(l) \ 20 | ll l; \ 21 | cin >> l; 22 | #define cind(d) \ 23 | double d; \ 24 | cin >> d; 25 | #define sz(x) ((int)(x).size()) 26 | 27 | #define loop(i, a, b) for (int i = a; i < b; ++i) 28 | #define loopr(i, a, b) for (int i = a; i >= b; --i) 29 | #define loops(i, a, b, step) for (int i = a; i < b; i += step) 30 | #define looprs(i, a, b, step) for (int i = a; i >= b; i -= step) 31 | 32 | #define ull unsigned long long int 33 | #define ll long long int 34 | #define P pair 35 | #define PLL pair 36 | #define PII pair 37 | #define PUU pair 38 | #define L list 39 | #define V vector 40 | #define D deque 41 | #define ST set 42 | #define MS multiset 43 | #define M map 44 | #define UM unordered_map 45 | #define mp make_pair 46 | #define eb emplace_back // use eb instead of pb its much faster 47 | #define pb push_back 48 | #define pf push_front 49 | #define MM multimap 50 | #define F first 51 | #define S second 52 | #define IT iterator 53 | #define RIT reverse_iterator 54 | 55 | #define FASTIO \ 56 | ios_base::sync_with_stdio(false); \ 57 | cin.tie(NULL); \ 58 | cout.tie(NULL); 59 | 60 | // file inputs. 61 | #define FILE_READ_IN freopen("input.txt", "r", stdin); 62 | #define FILE_READ_OUT freopen("output.txt", "w", stdout); 63 | 64 | using namespace std; 65 | 66 | // For ordered_set 67 | using namespace __gnu_pbds; 68 | template 69 | using ord_set = tree, rb_tree_tag, tree_order_statistics_node_update>; 70 | 71 | // constants 72 | const ll maxn = 1e5; 73 | const ll minn = 1e-9; 74 | const ll inf = 1e9; 75 | const double pi = acos(-1); 76 | 77 | // bits 78 | #define setBit(S, j) (S |= (1 << j)) 79 | #define clearBit(S, j) (S &= ~(1 << j)) 80 | #define toggleBit(S, j) (S ^= (1 << j)) 81 | 82 | // Power of two 83 | bool isPowerOfTwo(ll x) 84 | { 85 | return (x && (!(x & (x - 1)))); 86 | } 87 | 88 | // GCD and LCM 89 | ll gcd(ll a, ll b) 90 | { 91 | if (b == 0) 92 | return a; 93 | return gcd(b, a % b); 94 | } 95 | 96 | ll lcm(ll a, ll b) 97 | { 98 | return (a * b) / gcd(a, b); 99 | } 100 | 101 | // Fast Exponential 102 | ll fpow(ll b, ll exp) 103 | { 104 | if (exp == 0) 105 | return 1; 106 | ll t = fpow(b, exp / 2); 107 | 108 | if (exp & 1) 109 | return (((t % MOD) * (t % MOD) * (b % MOD)) % MOD); 110 | return (((t % MOD) * (t % MOD)) % MOD); 111 | } 112 | 113 | // Fast DivMod 114 | ll divmod(ll i, ll j) 115 | { 116 | i %= MOD; 117 | j %= MOD; 118 | return i * fpow(j, MOD - 2) % MOD; 119 | } 120 | 121 | //Number of digits in a number 122 | ll numOfDigits(ll n) 123 | { 124 | return floor(log10(n)) + 1; 125 | } 126 | 127 | // Parity checker 128 | bool getParity(unsigned int n) 129 | { 130 | bool parity = 0; 131 | while (n) 132 | { 133 | parity = !parity; 134 | n = n & (n - 1); 135 | } 136 | return parity; 137 | } 138 | 139 | //primality_test 140 | bool isprime(ll n) 141 | { 142 | if (n <= 1) 143 | return false; 144 | if (n <= 3) 145 | return true; 146 | if (n % 2 == 0 || n % 3 == 0) 147 | return false; 148 | for (ll i = 5; i * i <= n; i = i + 6) 149 | { 150 | if (n % i == 0 || n % (i + 2) == 0) 151 | { 152 | return false; 153 | } 154 | } 155 | return true; 156 | } 157 | 158 | bool isPalindrome(string::iterator low, string::iterator high) 159 | { 160 | while (low < high) 161 | { 162 | if (*low != *high) 163 | return false; 164 | low++; 165 | high--; 166 | } 167 | return true; 168 | } 169 | 170 | int possiblePalinByRemovingOneChar(string str) 171 | { 172 | int low = 0, high = str.length() - 1; 173 | 174 | while (low < high) 175 | { 176 | 177 | if (str[low] == str[high]) 178 | { 179 | low++; 180 | high--; 181 | } 182 | else 183 | { 184 | 185 | if (isPalindrome(str.begin() + low + 1, str.begin() + high)) 186 | return low; 187 | 188 | if (isPalindrome(str.begin() + low, str.begin() + high - 1)) 189 | return high; 190 | 191 | return -1; 192 | } 193 | } 194 | 195 | return -2; 196 | } 197 | 198 | int main() 199 | { 200 | FASTIO 201 | int t = 0; 202 | cin >> t; 203 | while (t--) 204 | { 205 | cins(str); 206 | int idx = possiblePalinByRemovingOneChar(str); 207 | if (idx != -1 && idx != -2) 208 | cout << idx << "\n"; 209 | else 210 | cout << -1 << "\n"; 211 | } 212 | return 0; 213 | } -------------------------------------------------------------------------------- /Resources.md: -------------------------------------------------------------------------------- 1 | 2 | ## Step 1: Choosing a language 3 | Firstly, you need to choose a programming language that you are most comfortable with and learn its syntax. It can be anything C, C++, Java, Python or any programming language. C++, C or Java is a faster programming language in comparison to any other language also it is allowed to be used in any coding challenge or interviews. So it’s good if you choose one out of these three. Most of the competitive programmers use C++ as a base language, so if you are still confused you can go with this. 4 | 5 | https://www.codingninjas.com/blog/2018/04/11/the-best-languages-for-competitive-programming/#:~:text=C%2B%2B%20is%20the%20most%20preferred,%2C%20stacks%2C%20arrays%2C%20etc. 6 | 7 | ## Step 2: Setting up an IDE 8 | You can look at a few blogs to set up IDE. Remember in rare cases output is compiler dependent so if you are in confusion then you can compare your output with CodeChef’s compiler. 9 | 10 | [What is your competitive Programming setup for contests?](https://codeforces.com/blog/entry/68025) 11 | 12 | https://www.quora.com/Being-a-competitive-programmer-which-is-the-best-IDE-to-use#:~:text=C%2B%2B%2FJava%20%3A%20People%20usually,and%20fun%20to%20work%20with. 13 | 14 | [Best IDE for Competitive Programming? - general](https://discuss.codechef.com/t/best-ide-for-competitive-programming/54541) 15 | 16 | 17 | ## Step 3: Getting familiar with your chosen language 18 | You can practise these few problems to get familiar with your chosen language in terms of CP input and output management. 19 | 20 | 1. https://www.hackerrank.com/challenges/mini-max-sum/problem 21 | 2. https://www.hackerrank.com/challenges/diagonal-difference/problem 22 | 3. https://www.hackerrank.com/challenges/time-conversion/problem 23 | 24 | ## Step 4: Kickstarting your Journey in competitive programming 25 | These resources will kickstart & boost your journey throughout your competitive programming and will make sure that you don't find yourself stuck in pitholes of CP. 26 | 27 | 1. [Competitive Programming 2.0. Welcome to the second blog in my series… | by Shubham Kumar Jha | The Aparoksha Blog](https://medium.com/the-aparoksha-blog/beginners-guide-to-competitive-programming-60300af1ee92) 28 | 2. [Getting started with the sport of competitive programming - Triveni Mahatha](https://www.hackerearth.com/practice/notes/getting-started-with-the-sport-of-programming/) 29 | 3. [Some useful C++ tricks for beginners in Competitive Programming](https://www.geeksforgeeks.org/some-useful-c-tricks-for-beginners-in-competitive-programming/?ref=rp) 30 | 31 | ## Step 5: The Art of Debugging in programming 32 | In any type of programming the one of the most quintessential thing is debugging but, it the most tiresome & tedious task (:p). To ease some your debugging tasks in CP, the resources given below might feel much necessary. 33 | 34 | 1. [Easy & pretty debugging code for C++](https://codeforces.com/blog/entry/3473) 35 | 2. [C++ tricks for competitive programming (for C++ 11)](https://www.geeksforgeeks.org/c-tricks-competitive-programming-c-11/) 36 | 3. [What is the best competitive programming debugging tips? I always code in Vim, Geedit, or Sublime, and I find debugging really tedious](https://www.quora.com/What-are-the-best-competitive-programming-debugging-tips-I-always-code-in-Vim-Geedit-or-Sublime-and-I-find-debugging-really-tedious). 37 | 38 | ## Step 6: Understand the Concept of Time and Space Complexity 39 | You need to find the best solution i.e optimal one learning these two concepts. So dig yourself into these two topics to know how much time and space an algorithm takes to solve a problem. 40 | 41 | 1. https://www.hackerearth.com/practice/basic-programming/complexity-analysis/time-and-space-complexity/tutorial/#:~:text=Time%20complexity%20of%20an%20algorithm,the%20length%20of%20the%20input. 42 | 2. [Understanding Time Complexity with Simple Examples](https://www.geeksforgeeks.org/understanding-time-complexity-simple-examples/) 43 | 3. [Space Complexity](https://www.geeksforgeeks.org/g-fact-86/). 44 | 45 | ## Step 7: AWESOMENESS OF MATH & DS/ALGO IN CP [Why?](https://www.geeksforgeeks.org/why-data-structures-and-algorithms-are-important-to-learn/) 46 | 47 | The core part for competitive programming is Ds / Algo + perfect amount of math in it to solve any problem with efficient time & space constraints and a proper implementation to solve it. 48 | 49 | 1. [An awesome list for competitive programming!](https://codeforces.com/blog/entry/23054) 50 | 2. [Must do Math for Competitive Programming](https://www.geeksforgeeks.org/math-in-competitive-programming/) 51 | 3. [Improving your Algorithms & Data Structure Skills | by Daniel Borowski | Tech x Talent](https://medium.com/coderbyte/how-to-get-good-at-algorithms-data-structures-d33d5163353f) 52 | 4. [Competitive Programmer's Handbook](https://cses.fi/book/book.pdf) 53 | 54 | ## Step 8: ADVANCED LEVEL GUIDES 55 | 56 | You can use these resources to strength your grips over harder & complex topics in competitive programming in your CP journey. 57 | 58 | 1. [Guide-to-Competitive-Programming-Learning-and-improving-Algorithms-through-Contests.pdf](https://drive.google.com/file/d/1Z8bVSt7Af8K7FStJrFLXdfa9Elp4kgAR/view) 59 | 2. [Data Structure and Algorithm]()https://drive.google.com/drive/folders/1szZmcER2CjAFbcqCLitTn_4nyv0wxUjn 60 | 3. [Algorithm Gym:: Graph Algorithms](https://codeforces.com/blog/entry/16221) 61 | 4. [Main Page - Competitive Programming Algorithms](https://cp-algorithms.com/) 62 | 63 | ## Some Important YouTube Videos for CP 64 | 65 | 1. [Starting Competitive Programming - Steps and Mistakes](https://www.youtube.com/watch?v=bVKHRtafgPc). 66 | 2. [Errichto/youtube: codes for my streams and YT videos](https://github.com/Errichto/youtube) 67 | 3. [Start you Journey in CP with AcadBoost/Kalpit Veerval](https://www.youtube.com/watch?v=wAQuoMjw9_g) 68 | --------------------------------------------------------------------------------