GeeksForGeeks - POTD | GFG POTD Answer
Закритий канал
1 218
Підписники
Немає даних24 години
-97 днів
-5730 день
Архів дописів
Flipkart GRiD 6.0✅ Hackathon 🏆 & Hiring 👨🏼🎓 👨🏼🎓 Graduation Year: 2025 / 2026 / 2027 / 2028 🔥 FullTime Role Salary: 32 LPA 👨🏼🎓 Internship Stipend: 1 Lakh / Month 🧩 Software Developer Role 🧩 🔗 tinyurl.com/Grid6-Software 🤖 Robotics 🤖 🔗 tinyurl.com/Grid6-Robotics 👨🏻💻 Information Security 👨🏻💻 🔗 tinyurl.com/Grid6-InfoSec
18th July : C++ Solution☝🏼
————————————————————
🙋🏻♂️Discussion ⁉️
Join ✅ @GFG_Answer
🔥 Win an Ipad 🔥
class Solution {
public:
int alternatingMaxLength(vector<int>& arr) {
int n=1,m=1;
for(int i=1;i<arr.size();i++){
if(arr[i-1]<arr[i]){
n=m+1;
}
if(arr[i]<arr[i-1]){
m=n+1;
}
else{
continue;
}
}
return max(n,m);
}
};17th July : C++ Solution☝🏼
————————————————————
🙋🏻♂️Discussion ⁉️
Join ✅ @GFG_Answer
🔥 Win an Ipad 🔥
class Solution {
public:
Node *createTree(vector<int> parent) {
unordered_map<int,Node*> nodes;
for(int i =0;i< parent.size();i++){
nodes[i] =new Node(i);
}
int rootval =-1;
for(int i =0;i< parent.size();i++){
int Par =parent[i];
int Child =i;
if(Par == -1){
rootval =i;
continue;
}
if(nodes[Par]->left == nullptr){
nodes[Par]->left =nodes[Child];
}else{
nodes[Par]->right =nodes[Child];
}
}
return nodes[rootval];
}
};🧩 Postman API Fundamentals 🧩
🧩 Student Expert 🧩
👨🏼🎓 Tutor ~ Ali Mustafa (Senior Dev)
🗓 Starting from 19th July'24
💡 Daily at 7:30 PM
⚡ Postman PREMIUM For 6 Month ✅
⚡ Master using API's with Postman 🧩
⚡ 100% Live Training 🌱
⚡ Student Expert Certificate 👨🏼🎓
🔥 Limited Edition Postman Swags 🔥
🤔 Why Wait ? Enroll Now
16th July : C++ Solution☝🏼
————————————————————
🙋🏻♂️Discussion ⁉️
Join ✅ @GFG_Answer
class Solution {
public:
string printString(string s, char ch, int count) {
string ans="";
for(auto i:s){
if(count <= 0) ans+=i;
if(i==ch) count--;
}
return ans;
}
};Best DSA Courses ?! Why ? (Write Something)
15th July : C++ Solution☝🏼
————————————————————
🙋🏻♂️Discussion ⁉️
Join ✅ @GFG_Answer
class Solution {
public:
string smallestNumber(int s, int d) {
if (9 * d < s) {
return "-1";
}
if (s > 9) {
return smallestNumber(s - 9, d - 1) + "9";
}
if (d == 1){
return to_string(s);
}
if (s > 1) {
return smallestNumber(1, d - 1) + to_string(s - 1);
}
return smallestNumber(1, d - 1) + "0";
}
};https://t.me/dogshouse_bot/join?startapp=Dj40QtOWQaS8R_sqjjlV_Q
Who let the DOGS out?
14th July : C++ Solution☝🏼
————————————————————
🙋🏻♂️Discussion ⁉️
Join ✅ @GFG_Answer
class Solution {
public:
void segregate0and1(vector<int> &arr) {
int n = arr.size();
int i =0;
int j =n-1;
while(j> i){
if(arr[i]==1 && arr[j]==0){
swap(arr[j],arr[i]);
i++;
j--;
}
else if(arr[i] ==1 && arr[j]== 1){
j--;
}
else if(arr[i] ==0 && arr[j]== 0){
i++;
}
else{
i++;
j--;
}
}
}
};12th July : C++ Solution☝🏼
————————————————————
🙋🏻♂️Discussion ⁉️
Join ✅ @GFG_Answer
🧩 New Courses Uploaded 🧩
class Solution {
public:
vector<int> shortestPath(int V, int m, vector<vector<int>>& edges) {
unordered_map<int,list<pair<int,int>>>adj;
for(auto&it:edges){
int u=it[0];
int v=it[1];
int weight=it[2];
adj[u].push_back({v,weight});
adj[v].push_back({u,weight});
}
vector<int>visited(V+1,0);
vector<int>dist(V+1,INT_MAX);
dist[1]=0;
priority_queue<pair<int,int>,vector<pair<int,int>>,greater<pair<int,int>>>pq;
pq.push({0,1});
vector<int>parent(V+1,-1);
while(!pq.empty()){
int node=pq.top().second;
pq.pop();
if(!visited[node]){
visited[node]=true;
for(auto v:adj[node]){
int nbr=v.first;
int weight=v.second;
if(dist[nbr]>dist[node]+weight){
dist[nbr]=dist[node]+weight;
pq.push({dist[nbr],nbr});
parent[nbr]=node;
}
}
}
}
if(parent[V]==-1)return {-1};
vector<int>path;
int t=V;
while(t!=-1){
path.push_back(t);
t=parent[t];
}
path.push_back(dist[V]);
reverse(path.begin(),path.end());
return path;
}
};12th July : C++ Solution☝🏼
————————————————————
🙋🏻♂️Discussion ⁉️
Join ✅ @GFG_Answer
🧩 New Courses Uploaded 🧩
class Solution {
public:
bool hasPathSum(Node* root, int target) {
if (root == nullptr) {
return false;
}
if (root->left == nullptr && root->right == nullptr) {
return target == root->data;
}
int remainingSum = target - root->data;
return hasPathSum(root->left, remainingSum) || hasPathSum(root->right, remainingSum);
}
};