Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions C++/h1.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// ie. if the string given is 'djhfacdadcaop' the longest palindrom is 'acdadca'
// which should be the return value for the function longest pallindrome(char* s).

#include<iostream>
#include<bits/stdc++.h>//librar
using namespace std;

void printSubStr(
Expand Down Expand Up @@ -31,15 +31,15 @@ int longestPalSubstr(string str)
if (str[i] == str[i + 1]) {
table[i][i + 1] = true;
start = i;
maxLength = 2;
maxLength =2;
}
}

for (int k = 3; k <= n; ++k) {
for (int i = 0; i < n - k; ++i) {
for (int i = 0; i < n - k+1; ++i) {// n-k to n-k+1
int j = i + k - 1;

if (table[i + 1][j] && str[i] == str[j]) {
if (table[i + 1][j-1] && str[i] == str[j]) {//j-1
table[i][j] = true;

if (k > maxLength) {
Expand All @@ -61,7 +61,7 @@ int longestPalSubstr(string str)
// Driver Code
int main()
{
string str = "forgeeksskeegfor";
string str = "forgeeksskeegrof";
cout << longestPalSubstr(str) << endl;
return 0;
}
Expand Down
Binary file added C++/h1.exe
Binary file not shown.
9 changes: 6 additions & 3 deletions C++/h2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,19 @@ int count(int coins[], int n, int sum)
for (i = 1; i < sum + 1; i++) {
for (j = 0; j < n; j++) {

x = (i - coins[j] >= 0) ? table[j][i - coins[j]] : 1;
//x = (i - coins[j] >= 0) ? table[j][i - coins[j]] : 1;
x = (i - coins[j] >= 0) ? table[i - coins[j]][j]: 0;



y = (j > 1) ? table[j - 1][i] : 1;
//y = (j > 1) ? table[j - 1][i] : 1;
y = (j >= 1) ? table[i][j - 1] : 0;


table[i][j] = x + y;
}
}
return table[sum-1][n - 1];
return table[sum][n-1]; //table[sum-1][n - 1]; table[sum][n-1]
}

// Driver Code
Expand Down
Binary file added C++/h2.exe
Binary file not shown.
4 changes: 2 additions & 2 deletions C++/m1.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ class Solution
public:
bool isPalindrome(string s)
{
int i = 0, j = s.size();
int i = 0, j = s.size()-1;

while (i < j)
{
Expand All @@ -34,7 +34,7 @@ class Solution
{
if (isPalindrome(s.substr(i, j)))
{
if (result.size() < j)
if (result.size() < s.substr(i,j).size())
result = s.substr(i, j + 1);
}
}
Expand Down
15 changes: 11 additions & 4 deletions C++/m2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class Solution {
vector<vector<int>> output;
for (int i = 0; i < nums.size(); i++){
int j = i + 1;
int k = i+j;
int k = nums.size()-1;
while (j < k) {
int sum = nums[i] + nums[j] + nums[k];
if (sum == target) {
Expand All @@ -28,8 +28,15 @@ class Solution {
}
}
}
for(auto triplets : s)
output.push_back(triplets);
return output;
for(auto triplets : s){
cout<<triplets[0]<<triplets[1]<<triplets[2];
output.push_back(triplets);}

}
};

int main(){
vector<int>nums={1,2,-3,1,-2,1};
Solution s;
s.threeSum(nums);
}
Binary file added C++/m2.exe
Binary file not shown.
7 changes: 5 additions & 2 deletions C++/m3.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ using namespace std;
char *initialize() {
char string[80];
// string = "hello"
char* ptr = string;
char* ptr ;
ptr = string;
return ptr;
}

Expand All @@ -16,8 +17,10 @@ void do_something_with(char* myval){

main() {
cout << "enter value for myval" << endl;
char *myval = initialize();
char *myval ;
myval = initialize();
cin >> *myval;
cout<<*myval;
cout << "Variable intialized" << endl;
do_something_with(myval);
}
Binary file added C++/m3.exe
Binary file not shown.
4 changes: 2 additions & 2 deletions C++/m5.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,13 @@ vector<int> spiralOrder(vector<vector<int> >& matrix)
int newX = x + dr[di];
int newY = y + dc[di];

if (0 <= newX || newX < m && 0 <= newY || newY < n
if (0 <= newX && newX < m && 0 <= newY && newY < n
&& !seen[newX][newY]) {
x = newX;
y = newY;
}
else {
di = (di + 1) / 4;
di = (di + 1) % 4;
x += dr[di];
y += dc[di];
}
Expand Down
2 changes: 1 addition & 1 deletion C++/m6.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#include<string>

int main(){
std :: string s = "Hello World";
std :: string s = NULL;

for(int i=0;i < s.length(); i++){
s[i] = toupper(s[i]);
Expand Down
Binary file added C++/m6.exe
Binary file not shown.
2 changes: 1 addition & 1 deletion C++/s1.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ using namespace std;
int reverse(int x) {
long r=0;
while(x){
r=r*10+x/10;
r=r*10+x%10;
x=x/10;
}
return r;
Expand Down
Binary file added C++/s1.exe
Binary file not shown.
2 changes: 1 addition & 1 deletion C++/s2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ int main(){
for(int i=0; i < myVec.size(); i++){
std :: cout << myVec[i] << std :: endl;
}
std :: cout << "Element at index 3: "<< myVec.at(3) << std::endl;
std :: cout << "Element at index 3: "<< myVec.at(2) << std::endl;

return 0;
}
Binary file added C++/s2.exe
Binary file not shown.
2 changes: 1 addition & 1 deletion C++/s3.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ void ineedj(void) {
}

main() {
int j;
//int j;
j = foo(i);
ineedj();
}
8 changes: 4 additions & 4 deletions C++/s4.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,16 @@
#include<iostream>
#include <bits/stdc++.h>
using namespace std;
#define Random(n) random()%n
#define Random(n) random(n)%n

int random(){
int random(int n){
srand(time(0));
return rand();
return rand()%n;
}


int main(void){
int i=6, j=7;
int i=6, j=9;
int val = Random(j-i+1);

cout << val << endl;
Expand Down
Binary file added C++/s4.exe
Binary file not shown.
Binary file added C++/s5.exe
Binary file not shown.
8 changes: 7 additions & 1 deletion C++/s6.cpp
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
// to find the largest sum of subarray
#include<iostream>
#include<climits>
using namespace std;

int maxSubArraySum(int a[], int size)
{
int max_so_far = INT_MIN, max_ending_here;
int max_so_far = 0, max_ending_here=0;

for (int i = 0; i < size; i++) {
max_ending_here = max_ending_here + a[i];
Expand All @@ -16,3 +17,8 @@ int maxSubArraySum(int a[], int size)
}
return max_so_far;
}
int main(){
int arr[]={-5,4,3,-2,1};
cout<<maxSubArraySum(arr,5);
return 0;
}
Binary file added C++/s6.exe
Binary file not shown.