< Ace Coding /> ๐Ÿš€
337 subscribers
54 photos
2 videos
95 files
66 links
Welcome to Ace Coding! Join us for tips, tutorials, and insights on coding and software engineering. Stay updated with the latest content and elevate your programming skills!Let's learn and grow together in the world of software engineering!
Download Telegram
Audio
๐Ÿš€ DSA Intro Audio ๐ŸŽง

Boost your learning by engaging multiple senses! Weโ€™re excited to share a high-quality audio introduction to Data Structures & Algorithms. Perfect for listening anytime, anywhere.

๐Ÿ’ก Sources:

โœจ A2SV notes
๐Ÿ“š Grokking Algorithms
๐Ÿ”‘ Cracking the Coding Interview
๐Ÿ“ Class Notes (Ch. 1 & 2)
๐Ÿ† Codeforces & HackerRank
๐Ÿ’ป GeeksForGeeks

๐Ÿ‘‰ Dive in and make studying more immersive and effective! ๐ŸŒŸ

๐ŸŒŸ๐Ÿš€ @AceCoding Presents! ๐Ÿš€๐ŸŒŸ
๐Ÿ‘1
< Ace Coding /> ๐Ÿš€
https://www.hackerrank.com/challenges/insertionsort1/problem
โœ… First try the question by yourself and then try to compare your solution with mine:
#!/bin/python3

import math
import os
import random
import re
import sys

#
# Complete the 'insertionSort1' function below.
#
# The function accepts following parameters:
# 1. INTEGER n
# 2. INTEGER_ARRAY arr
#

def insertionSort1(n, arr):
# Write your code here
for i in range(n):
j = i
curr = arr[i]
if curr < arr[j-1]:
while j > 0 and curr < arr[j-1]:
arr[j]= arr[j-1]
j-=1
print(*arr)

if j != i:
arr[j] = curr
print(*arr)



if __name__ == '__main__':
n = int(input().strip())

arr = list(map(int, input().rstrip().split()))

insertionSort1(n, arr)
๐Ÿ‘2
โœ…๐Ÿ’ป Here is a C++ implementation for the above question.
#include <bits/stdc++.h>

using namespace std;

string ltrim(const string &);
string rtrim(const string &);
vector<string> split(const string &);

/*
* Complete the 'insertionSort1' function below.
*
* The function accepts following parameters:
* 1. INTEGER n
* 2. INTEGER_ARRAY arr
*/

void insertionSort1(int n, vector<int> arr) {
for (int i = 1; i < n; i++) {
int curr = arr[i];
int j = i;

if (curr < arr[j - 1]) {
while (j > 0 && curr < arr[j - 1]) {
arr[j] = arr[j - 1];
j--;

for (int k = 0; k < n; k++) {
cout << arr[k] << " ";
}
cout << endl;
}

if (j != i) {
arr[j] = curr;
for (int k = 0; k < n; k++) {
cout << arr[k] << " ";
}
cout << endl;
}
}
}
}

int main()
{
string n_temp;
getline(cin, n_temp);

int n = stoi(ltrim(rtrim(n_temp)));

string arr_temp_temp;
getline(cin, arr_temp_temp);

vector<string> arr_temp = split(rtrim(arr_temp_temp));

vector<int> arr(n);

for (int i = 0; i < n; i++) {
int arr_item = stoi(arr_temp[i]);

arr[i] = arr_item;
}

insertionSort1(n, arr);

return 0;
}

string ltrim(const string &str) {
string s(str);

s.erase(
s.begin(),
find_if(s.begin(), s.end(), not1(ptr_fun<int, int>(isspace)))
);

return s;
}

string rtrim(const string &str) {
string s(str);

s.erase(
find_if(s.rbegin(), s.rend(), not1(ptr_fun<int, int>(isspace))).base(),
s.end()
);

return s;
}

vector<string> split(const string &str) {
vector<string> tokens;

string::size_type start = 0;
string::size_type end = 0;

while ((end = str.find(" ", start)) != string::npos) {
tokens.push_back(str.substr(start, end - start));

start = end + 1;
}

tokens.push_back(str.substr(start));

return tokens;
}
๐Ÿ‘1
< Ace Coding /> ๐Ÿš€
https://www.hackerrank.com/challenges/countingsort1/problem
๐Ÿ’ป Solution:
def countingSort(arr):
# Write your code here
count = [0]*100
for n in arr:
count[n] += 1

return count
โœ…C++ version:
vector<int> countingSort(vector<int> arr) {
vector<int> count(100); // arrays connot be returned so make sure to use vectors
for (int i = 0; i < arr.size(); i++){
// for vectors use size() method the length() method works for strings only
count[arr[i]]++;
}
return count;
}
๐Ÿ‘จโ€๐Ÿ’ป This question is flagged as EASY on LeetCode, but trust me, itโ€™s the kind of 'easy' that makes you question your life choices. youโ€™ll definitely give it a hard stare. ๐Ÿคจ
Acceptance Rate = 62%

๐Ÿ’ฌ If you're new to leetcode don't bother trying to solve it I will share more feasible questions for beginners.


https://leetcode.com/problems/sort-even-and-odd-indices-independently/description/
#LeetCode #DSA #HardEasy
๐Ÿ–ฅ Solution:
class Solution:
def sortEvenOdd(self, nums: List[int]) -> List[int]:
n = len(nums)

even_indexes = [nums[i] for i in range(0, n, 2)]
# range(start, end, step)
odd_indexes = [nums[i] for i in range(1, n, 2)]

even_indexes.sort()
odd_indexes.sort(reverse=True)

even_ptr = odd_ptr = 0
res = []
for i in range(n):
if i % 2 == 0:
res.append(even_indexes[even_ptr])
even_ptr += 1
else:
res.append(odd_indexes[odd_ptr])
odd_ptr += 1

return res
โœ… Hereโ€™s where things get a bit off . You might already know this technique, but for those who donโ€™t, Iโ€™ll break it down. Just ask.

๐Ÿฌ This is a beautiful and super helpful piece of Python syntax sugar. The Pythonistas โœจ๐Ÿ out there might already know it, but for everyone else, for your long-term success in DSA, leetcode or coding interviews learn Python ASAP ๐Ÿ’ป๐Ÿ

class Solution:
def sortEvenOdd(self, nums: List[int]) -> List[int]:
nums[::2] = sorted(nums[::2])
nums[1::2] = sorted(nums[1::2], reverse=True)
return nums
๐Ÿ”ฅ1
๐Ÿ’ป C++ version:
// #include <bits/std++.h> 
// using namespace std;
// If you are running it locally make sure to include the above in your code

class Solution {
public:
vector<int> sortEvenOdd(vector<int>& nums) {
int n = nums.size();

vector<int> even_indexes;
vector<int> odd_indexes;

for (int i = 0; i < n; i += 2) {
even_indexes.push_back(nums[i]);
}

for (int i = 1; i < n; i += 2) {
odd_indexes.push_back(nums[i]);
}

sort(even_indexes.begin(), even_indexes.end());
sort(odd_indexes.rbegin(), odd_indexes.rend());

int even_ptr = 0, odd_ptr = 0;
vector<int> res(n);

for (int i = 0; i < n; ++i) {
if (i % 2 == 0) {
res[i] = even_indexes[even_ptr++];
} else {
res[i] = odd_indexes[odd_ptr++];
}
}

return res;
}
};
๐Ÿ‘4
Forwarded from GDG On Campus AASTU (๐š‹๐š’๐š›๐šž๐š” ๐š–)
๐Ÿš€Hey AASTU students! ๐Ÿš€

Are you curious about tech and looking for ways to connect with like-minded individuals? ๐Ÿง

Join us for an exciting Info Session organized by Google Developer Groups (GDG) On Campus - AASTU in collaboration with AASTU Software Engineering Association (SEA)!

Whatโ€™s in it for you? ๐Ÿ™‚

Get an introduction to Google Developer Groups (GDG) and AASTU SEA, and discover how joining these communities can enhance your tech journey.

Meet the GDG and SEA Campus Leads and get insights into upcoming events, workshops, and more.

Explore how GDG and SEA can support your passion for tech, from beginner to advanced skills.

Network with other tech enthusiasts and make new friends!

Event Details ๐ŸŽ‡

๐Ÿ—“ Date: 13th November 2024
โฑ Time: 8:30 - 11:00 Local Time
๐Ÿ“ Location: AASTU campus (RED CARPET)  

๐Ÿ‘‰๐Ÿ‘‰๐Ÿ‘‰ RSVP Register Here  ๐Ÿ‘ˆ๐Ÿ‘ˆ๐Ÿ‘ˆ

Who should attend? ๐Ÿ’Ž

Everyone is welcome! Whether you're a complete beginner, an aspiring developer, or already deep into coding, this session is for you. No prior experience is required, just a passion for learning and connecting!

Follow Us ๐ŸŒŽ

Stay updated by following our social media for more details and updates. Connect with us on:

Linkedin
Instagram
Telegram
Newsletter

โญ๏ธ Come ready to learn, connect, and start your tech journey with GDG and AASTU SEA at AASTU!

#GDGAASTU #AASTUSEA #InfoSession #TechForAll #LearnAndConnect #AASTUEvents #GDGOnCampus #NetworkAndGrow
Please open Telegram to view this post
VIEW IN TELEGRAM
๐ŸŽ‰ Quiz Time! ๐Ÿš€

Weโ€™re kicking off our Exam Prep Quiz for Computer Organization & Architecture! ๐Ÿ–ฅ Get ready for a fun round of questions to test your knowledge! ๐Ÿง  Click your answer below and letโ€™s see whoโ€™s got this! ๐Ÿ’ช๐Ÿ“Š

๐ŸŒŸ๐Ÿš€ @AceCoding Presents! ๐Ÿš€๐ŸŒŸ
๐ŸŽ‰ Warm-Up Time!
๐Ÿš€ Letโ€™s get started with some easy questions to warm up for the Computer Organization & Architecture exam! ๐Ÿง  Donโ€™t stress, weโ€™ll take it slow to get the ball rolling! ๐Ÿ’ช Answer the first question below and letโ€™s dive in! ๐Ÿ“š
Forwarded from โ™ค
Forwarded from โ™ค
2. ๐Ÿง  True or False: A register in the CPU is a small storage location that holds data temporarily.
Anonymous Quiz
71%
A) True
29%
B) False