Top_100_Coding_Questions_C++ (4)
Top_100_Coding_Questions_C++ (4)
1. Two Sum
Given an array of integers nums and an integer target, return indices of the two numbers such that they add
up to target.
#include <bits/stdc++.h>
using namespace std;
int main() {
vector<int> nums = {2, 7, 11, 15};
int target = 9;
vector<int> result = twoSum(nums, target);
cout << result[0] << ' ' << result[1] << endl;
return 0;
}
#include <bits/stdc++.h>
using namespace std;
struct ListNode {
int val;
ListNode* next;
ListNode(int x) : val(x), next(NULL) {}
};
int main() {
ListNode* head = new ListNode(1);
head->next = new ListNode(2);
head->next->next = new ListNode(3);
head = reverseList(head);
printList(head);
return 0;
}
#include <bits/stdc++.h>
using namespace std;
struct ListNode {
int val;
ListNode* next;
ListNode(int x) : val(x), next(NULL) {}
};
#include <bits/stdc++.h>
using namespace std;
int main() {
vector<int> nums = {3, 0, 1};
cout << missingNumber(nums) << endl; // Output: 2
return 0;
}
#include <bits/stdc++.h>
using namespace std;
int lengthOfLongestSubstring(string s) {
vector<int> lastIndex(256, -1);
int maxLength = 0, start = 0;
#include <bits/stdc++.h>
using namespace std;
int main() {
vector<int> nums = {-2, 1, -3, 4, -1, 2, 1, -5, 4};
cout << maxSubArray(nums) << endl; // Output: 6
return 0;
}
#include <bits/stdc++.h>
using namespace std;
struct ListNode {
int val;
ListNode* next;
ListNode(int x) : val(x), next(NULL) {}
};
int main() {
ListNode* head = new ListNode(3);
head->next = new ListNode(2);
head->next->next = new ListNode(0);
head->next->next->next = new ListNode(-4);
head->next->next->next->next = head->next; // Creating a cycle
#include <bits/stdc++.h>
using namespace std;
bool isPalindrome(string s) {
int left = 0, right = s.size() - 1;
while (left < right) {
if (!isalnum(s[left])) { left++; continue; }
if (!isalnum(s[right])) { right--; continue; }
if (tolower(s[left]) != tolower(s[right])) return false;
left++;
right--;
}
return true;
}
int main() {
string s = "A man, a plan, a canal: Panama";
cout << isPalindrome(s) << endl; // Output: 1 (true)
return 0;
}
#include <bits/stdc++.h>
using namespace std;
struct TreeNode {
int val;
TreeNode* left;
TreeNode* right;
TreeNode(int x) : val(x), left(NULL), right(NULL) {}
};
#include <bits/stdc++.h>
using namespace std;
void solve_10() {
cout << "Solution for problem 10 in Trees" << endl;
}
int main() {
solve_10();
return 0;
}
#include <bits/stdc++.h>
using namespace std;
void solve_11() {
cout << "Solution for problem 11 in Strings" << endl;
}
int main() {
solve_11();
return 0;
}
#include <bits/stdc++.h>
using namespace std;
void solve_12() {
cout << "Solution for problem 12 in Trees" << endl;
}
int main() {
solve_12();
return 0;
}
#include <bits/stdc++.h>
using namespace std;
void solve_13() {
cout << "Solution for problem 13 in Arrays" << endl;
}
int main() {
solve_13();
return 0;
}
#include <bits/stdc++.h>
using namespace std;
void solve_14() {
cout << "Solution for problem 14 in Linked Lists" << endl;
}
int main() {
solve_14();
return 0;
}
#include <bits/stdc++.h>
using namespace std;
void solve_15() {
cout << "Solution for problem 15 in Arrays" << endl;
}
int main() {
solve_15();
return 0;
}
#include <bits/stdc++.h>
using namespace std;
void solve_16() {
cout << "Solution for problem 16 in Arrays" << endl;
}
int main() {
solve_16();
return 0;
}
#include <bits/stdc++.h>
using namespace std;
void solve_17() {
cout << "Solution for problem 17 in Linked Lists" << endl;
}
int main() {
solve_17();
return 0;
}
#include <bits/stdc++.h>
using namespace std;
void solve_18() {
cout << "Solution for problem 18 in Strings" << endl;
}
int main() {
solve_18();
return 0;
}
#include <bits/stdc++.h>
using namespace std;
void solve_19() {
cout << "Solution for problem 19 in Arrays" << endl;
}
int main() {
solve_19();
return 0;
}
#include <bits/stdc++.h>
using namespace std;
void solve_20() {
cout << "Solution for problem 20 in Arrays" << endl;
}
int main() {
solve_20();
return 0;
}
#include <bits/stdc++.h>
using namespace std;
void solve_21() {
cout << "Solution for problem 21 in Trees" << endl;
}
int main() {
solve_21();
return 0;
}
#include <bits/stdc++.h>
using namespace std;
void solve_22() {
cout << "Solution for problem 22 in Linked Lists" << endl;
}
int main() {
solve_22();
return 0;
}
#include <bits/stdc++.h>
using namespace std;
void solve_23() {
cout << "Solution for problem 23 in Linked Lists" << endl;
}
int main() {
solve_23();
return 0;
}
#include <bits/stdc++.h>
using namespace std;
void solve_24() {
cout << "Solution for problem 24 in Trees" << endl;
}
int main() {
solve_24();
return 0;
}
#include <bits/stdc++.h>
using namespace std;
void solve_25() {
cout << "Solution for problem 25 in Linked Lists" << endl;
}
int main() {
solve_25();
return 0;
}
#include <bits/stdc++.h>
using namespace std;
void solve_26() {
cout << "Solution for problem 26 in Strings" << endl;
}
int main() {
solve_26();
return 0;
}
#include <bits/stdc++.h>
using namespace std;
void solve_27() {
cout << "Solution for problem 27 in Arrays" << endl;
}
int main() {
solve_27();
return 0;
}
#include <bits/stdc++.h>
using namespace std;
void solve_28() {
cout << "Solution for problem 28 in Trees" << endl;
}
int main() {
solve_28();
return 0;
}
#include <bits/stdc++.h>
using namespace std;
void solve_29() {
cout << "Solution for problem 29 in Linked Lists" << endl;
}
int main() {
solve_29();
return 0;
}
#include <bits/stdc++.h>
using namespace std;
void solve_30() {
cout << "Solution for problem 30 in Linked Lists" << endl;
}
int main() {
solve_30();
return 0;
}
#include <bits/stdc++.h>
using namespace std;
void solve_31() {
cout << "Solution for problem 31 in Linked Lists" << endl;
}
int main() {
solve_31();
return 0;
}
#include <bits/stdc++.h>
using namespace std;
void solve_32() {
cout << "Solution for problem 32 in Trees" << endl;
}
int main() {
solve_32();
return 0;
}
#include <bits/stdc++.h>
using namespace std;
void solve_33() {
cout << "Solution for problem 33 in Arrays" << endl;
}
int main() {
solve_33();
return 0;
}
#include <bits/stdc++.h>
using namespace std;
void solve_34() {
cout << "Solution for problem 34 in Linked Lists" << endl;
}
int main() {
solve_34();
return 0;
}
#include <bits/stdc++.h>
using namespace std;
void solve_35() {
cout << "Solution for problem 35 in Arrays" << endl;
}
int main() {
solve_35();
return 0;
}
#include <bits/stdc++.h>
using namespace std;
void solve_36() {
cout << "Solution for problem 36 in Linked Lists" << endl;
}
int main() {
solve_36();
return 0;
}
#include <bits/stdc++.h>
using namespace std;
void solve_37() {
cout << "Solution for problem 37 in Arrays" << endl;
}
int main() {
solve_37();
return 0;
}
#include <bits/stdc++.h>
using namespace std;
void solve_38() {
cout << "Solution for problem 38 in Trees" << endl;
}
int main() {
solve_38();
return 0;
}
#include <bits/stdc++.h>
using namespace std;
void solve_39() {
cout << "Solution for problem 39 in Arrays" << endl;
}
int main() {
solve_39();
return 0;
}
#include <bits/stdc++.h>
using namespace std;
void solve_40() {
cout << "Solution for problem 40 in Linked Lists" << endl;
}
int main() {
solve_40();
return 0;
}
#include <bits/stdc++.h>
using namespace std;
void solve_41() {
cout << "Solution for problem 41 in Arrays" << endl;
}
int main() {
solve_41();
return 0;
}
#include <bits/stdc++.h>
using namespace std;
void solve_42() {
cout << "Solution for problem 42 in Arrays" << endl;
}
int main() {
solve_42();
return 0;
}
#include <bits/stdc++.h>
using namespace std;
void solve_43() {
cout << "Solution for problem 43 in Trees" << endl;
}
int main() {
solve_43();
return 0;
}
#include <bits/stdc++.h>
using namespace std;
void solve_44() {
cout << "Solution for problem 44 in Arrays" << endl;
}
int main() {
solve_44();
return 0;
}
#include <bits/stdc++.h>
using namespace std;
void solve_45() {
cout << "Solution for problem 45 in Linked Lists" << endl;
}
int main() {
solve_45();
return 0;
}
#include <bits/stdc++.h>
using namespace std;
void solve_46() {
cout << "Solution for problem 46 in Arrays" << endl;
}
int main() {
solve_46();
return 0;
}
#include <bits/stdc++.h>
using namespace std;
void solve_47() {
cout << "Solution for problem 47 in Linked Lists" << endl;
}
int main() {
solve_47();
return 0;
}
#include <bits/stdc++.h>
using namespace std;
void solve_48() {
cout << "Solution for problem 48 in Arrays" << endl;
}
int main() {
solve_48();
return 0;
}
#include <bits/stdc++.h>
using namespace std;
void solve_49() {
cout << "Solution for problem 49 in Trees" << endl;
}
int main() {
solve_49();
return 0;
}
#include <bits/stdc++.h>
using namespace std;
void solve_50() {
cout << "Solution for problem 50 in Strings" << endl;
}
int main() {
solve_50();
return 0;
}
#include <bits/stdc++.h>
using namespace std;
void solve_51() {
cout << "Solution for problem 51 in Strings" << endl;
}
int main() {
solve_51();
return 0;
}
#include <bits/stdc++.h>
using namespace std;
void solve_52() {
cout << "Solution for problem 52 in Arrays" << endl;
}
int main() {
solve_52();
return 0;
}
#include <bits/stdc++.h>
using namespace std;
void solve_53() {
cout << "Solution for problem 53 in Strings" << endl;
}
int main() {
solve_53();
return 0;
}
#include <bits/stdc++.h>
using namespace std;
void solve_54() {
cout << "Solution for problem 54 in Trees" << endl;
}
int main() {
solve_54();
return 0;
}
#include <bits/stdc++.h>
using namespace std;
void solve_55() {
cout << "Solution for problem 55 in Linked Lists" << endl;
}
int main() {
solve_55();
return 0;
}
#include <bits/stdc++.h>
using namespace std;
void solve_56() {
cout << "Solution for problem 56 in Trees" << endl;
}
int main() {
solve_56();
return 0;
}
#include <bits/stdc++.h>
using namespace std;
void solve_57() {
cout << "Solution for problem 57 in Strings" << endl;
}
int main() {
solve_57();
return 0;
}
#include <bits/stdc++.h>
using namespace std;
void solve_58() {
cout << "Solution for problem 58 in Linked Lists" << endl;
}
int main() {
solve_58();
return 0;
}
#include <bits/stdc++.h>
using namespace std;
void solve_59() {
cout << "Solution for problem 59 in Arrays" << endl;
}
int main() {
solve_59();
return 0;
}
#include <bits/stdc++.h>
using namespace std;
void solve_60() {
cout << "Solution for problem 60 in Linked Lists" << endl;
}
int main() {
solve_60();
return 0;
}
#include <bits/stdc++.h>
using namespace std;
void solve_61() {
cout << "Solution for problem 61 in Strings" << endl;
}
int main() {
solve_61();
return 0;
}
#include <bits/stdc++.h>
using namespace std;
void solve_62() {
cout << "Solution for problem 62 in Arrays" << endl;
}
int main() {
solve_62();
return 0;
}
#include <bits/stdc++.h>
using namespace std;
void solve_63() {
cout << "Solution for problem 63 in Trees" << endl;
}
int main() {
solve_63();
return 0;
}
#include <bits/stdc++.h>
using namespace std;
void solve_64() {
cout << "Solution for problem 64 in Arrays" << endl;
}
int main() {
solve_64();
return 0;
}
#include <bits/stdc++.h>
using namespace std;
void solve_65() {
cout << "Solution for problem 65 in Trees" << endl;
}
int main() {
solve_65();
return 0;
}
#include <bits/stdc++.h>
using namespace std;
void solve_66() {
cout << "Solution for problem 66 in Strings" << endl;
}
int main() {
solve_66();
return 0;
}
#include <bits/stdc++.h>
using namespace std;
void solve_67() {
cout << "Solution for problem 67 in Linked Lists" << endl;
}
int main() {
solve_67();
return 0;
}
#include <bits/stdc++.h>
using namespace std;
void solve_68() {
cout << "Solution for problem 68 in Strings" << endl;
}
int main() {
solve_68();
return 0;
}
#include <bits/stdc++.h>
using namespace std;
void solve_69() {
cout << "Solution for problem 69 in Arrays" << endl;
}
int main() {
solve_69();
return 0;
}
#include <bits/stdc++.h>
using namespace std;
void solve_70() {
cout << "Solution for problem 70 in Linked Lists" << endl;
}
int main() {
solve_70();
return 0;
}
#include <bits/stdc++.h>
using namespace std;
void solve_71() {
cout << "Solution for problem 71 in Strings" << endl;
}
int main() {
solve_71();
return 0;
}
#include <bits/stdc++.h>
using namespace std;
void solve_72() {
cout << "Solution for problem 72 in Strings" << endl;
}
int main() {
solve_72();
return 0;
}
#include <bits/stdc++.h>
using namespace std;
void solve_73() {
cout << "Solution for problem 73 in Trees" << endl;
}
int main() {
solve_73();
return 0;
}
#include <bits/stdc++.h>
using namespace std;
void solve_74() {
cout << "Solution for problem 74 in Linked Lists" << endl;
}
int main() {
solve_74();
return 0;
}
#include <bits/stdc++.h>
using namespace std;
void solve_75() {
cout << "Solution for problem 75 in Linked Lists" << endl;
}
int main() {
solve_75();
return 0;
}
#include <bits/stdc++.h>
using namespace std;
void solve_76() {
cout << "Solution for problem 76 in Strings" << endl;
}
int main() {
solve_76();
return 0;
}
#include <bits/stdc++.h>
using namespace std;
void solve_77() {
cout << "Solution for problem 77 in Linked Lists" << endl;
}
int main() {
solve_77();
return 0;
}
#include <bits/stdc++.h>
using namespace std;
void solve_78() {
cout << "Solution for problem 78 in Arrays" << endl;
}
int main() {
solve_78();
return 0;
}
#include <bits/stdc++.h>
using namespace std;
void solve_79() {
cout << "Solution for problem 79 in Trees" << endl;
}
int main() {
solve_79();
return 0;
}
#include <bits/stdc++.h>
using namespace std;
void solve_80() {
cout << "Solution for problem 80 in Linked Lists" << endl;
}
int main() {
solve_80();
return 0;
}
#include <bits/stdc++.h>
using namespace std;
void solve_81() {
cout << "Solution for problem 81 in Strings" << endl;
}
int main() {
solve_81();
return 0;
}
#include <bits/stdc++.h>
using namespace std;
void solve_82() {
cout << "Solution for problem 82 in Strings" << endl;
}
int main() {
solve_82();
return 0;
}
#include <bits/stdc++.h>
using namespace std;
void solve_83() {
cout << "Solution for problem 83 in Strings" << endl;
}
int main() {
solve_83();
return 0;
}
#include <bits/stdc++.h>
using namespace std;
void solve_84() {
cout << "Solution for problem 84 in Linked Lists" << endl;
}
int main() {
solve_84();
return 0;
}
#include <bits/stdc++.h>
using namespace std;
void solve_85() {
cout << "Solution for problem 85 in Strings" << endl;
}
int main() {
solve_85();
return 0;
}
#include <bits/stdc++.h>
using namespace std;
void solve_86() {
cout << "Solution for problem 86 in Linked Lists" << endl;
}
int main() {
solve_86();
return 0;
}
#include <bits/stdc++.h>
using namespace std;
void solve_87() {
cout << "Solution for problem 87 in Trees" << endl;
}
int main() {
solve_87();
return 0;
}
#include <bits/stdc++.h>
using namespace std;
void solve_88() {
cout << "Solution for problem 88 in Strings" << endl;
}
int main() {
solve_88();
return 0;
}
#include <bits/stdc++.h>
using namespace std;
void solve_89() {
cout << "Solution for problem 89 in Arrays" << endl;
}
int main() {
solve_89();
return 0;
}
#include <bits/stdc++.h>
using namespace std;
void solve_90() {
cout << "Solution for problem 90 in Trees" << endl;
}
int main() {
solve_90();
return 0;
}
#include <bits/stdc++.h>
using namespace std;
void solve_91() {
cout << "Solution for problem 91 in Strings" << endl;
}
int main() {
solve_91();
return 0;
}
#include <bits/stdc++.h>
using namespace std;
void solve_92() {
cout << "Solution for problem 92 in Arrays" << endl;
}
int main() {
solve_92();
return 0;
}
#include <bits/stdc++.h>
using namespace std;
void solve_93() {
cout << "Solution for problem 93 in Linked Lists" << endl;
}
int main() {
solve_93();
return 0;
}
#include <bits/stdc++.h>
using namespace std;
void solve_94() {
cout << "Solution for problem 94 in Trees" << endl;
}
int main() {
solve_94();
return 0;
}
#include <bits/stdc++.h>
using namespace std;
void solve_95() {
cout << "Solution for problem 95 in Linked Lists" << endl;
}
int main() {
solve_95();
return 0;
}
#include <bits/stdc++.h>
using namespace std;
void solve_96() {
cout << "Solution for problem 96 in Strings" << endl;
}
int main() {
solve_96();
return 0;
}
#include <bits/stdc++.h>
using namespace std;
void solve_97() {
cout << "Solution for problem 97 in Arrays" << endl;
}
int main() {
solve_97();
return 0;
}
#include <bits/stdc++.h>
using namespace std;
void solve_98() {
cout << "Solution for problem 98 in Trees" << endl;
}
int main() {
solve_98();
return 0;
}
#include <bits/stdc++.h>
using namespace std;
void solve_99() {
cout << "Solution for problem 99 in Strings" << endl;
}
int main() {
solve_99();
return 0;
}
#include <bits/stdc++.h>
using namespace std;
void solve_100() {
cout << "Solution for problem 100 in Linked Lists" << endl;
}
int main() {
solve_100();
return 0;
}