Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

839 #1699

Closed
wants to merge 2 commits into from
Closed

839 #1699

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
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
82 changes: 41 additions & 41 deletions 4.BST/Question_2.cpp
Original file line number Diff line number Diff line change
@@ -1,42 +1,42 @@
#include<iostream>
#include<vector>
using namespace std;
/*Tree node definiton*/
struct TreeNode{
int data;
TreeNode *left;
TreeNode *right;
TreeNode(int x){
data=x;
left=right=NULL;
}
};
int preorder_index=0;
TreeNode* buildTree(vector<int> &preorder,vector<int> &indexOfinorder,int start,int end){
if(start<=end){
TreeNode *node = new TreeNode(preorder[preorder_index]);
int inorder_index = /*TODO*/ ;
node->left = /*TODO*/;
node->right = /*TODO*/;
return /*TODO*/;
}
else
return /*TODO*/;
}
void print_preorder(TreeNode *root){
/*TODO*/
}
void print_inorder(TreeNode *root){
/*TODO*/
}
int main(){
vector<int> preorder = {7,4,2, 3, 6, 5, 12, 9, 8, 11, 19,15, 20},indexOfinorder={5,2,0,1,4,3,9,7,6,8,11,10,12};
TreeNode *root = buildTree(preorder,indexOfinorder,0,indexOfinorder.size()-1);
print_preorder(root);cout<<endl;
print_inorder(root);cout<<endl;
#include<iostream>
#include<vector>

using namespace std;

/*Tree node definiton*/
struct TreeNode{
int data;
TreeNode *left;
TreeNode *right;
TreeNode(int x){
data=x;
left=right=NULL;
}
};
int preorder_index=0;
TreeNode* buildTree(vector<int> &preorder,vector<int> &indexOfinorder,int start,int end){
if(start<=end){
TreeNode *node = new TreeNode(preorder[preorder_index]);
int inorder_index = /*TODO*/ ;
node->left = /*TODO*/;
node->right = /*TODO*/;
return /*TODO*/;
}
else
return /*TODO*/;
}

void print_preorder(TreeNode *root){
/*TODO*/
}

void print_inorder(TreeNode *root){
/*TODO*/
}

int main(){
vector<int> preorder = {7,4,2, 3, 6, 5, 12, 9, 8, 11, 19,15, 20},indexOfinorder={5,2,0,1,4,3,9,7,6,8,11,10,12};
TreeNode *root = buildTree(preorder,indexOfinorder,0,indexOfinorder.size()-1);
print_preorder(root);cout<<endl;
print_inorder(root);cout<<endl;
}
4 changes: 2 additions & 2 deletions 4.BST/TestCases/TestCase_1.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
150
3743 3388 118 1 36 45 1016 815 766 496 464 280 741 526 761 755 756 785 801 898 911 932 1005 1339 1036 1030 1024 1180 1283 1200 1225 3207 2096 1586 1579 1479 1362 1459 1851 1643 1627 1730 1739 2001 2014 2329 2254 2326 2993 2607 2490 2408 2877 2708 2757 2977 3094 3074 3024 3269 3383 3715 3609 3436 3435 3719 5803 5204 4265 4254 3946 4934 4840 4694 4314 4814 4907 4917 4984 4951 5196 5397 5316 5220 5352 5557 5435 5452 5796 5634 9352 6372 6294 6015 5844 5834 5835 5873 6263 9301 8847 7531 6380 6677 6567 6603 7161 6942 6800 6699 6694 6784 6821 6963 7155 7053 7229 7278 8154 7968 7538 7591 7575 7928 7657 7726 7814 8119 8206 8181 8228 8734 8330 8826 8782 8983 8968 9099 9008 9081 9287 9173 9755 9692 9386 9524 9631 9567 9668 9900
150
3743 3388 118 1 36 45 1016 815 766 496 464 280 741 526 761 755 756 785 801 898 911 932 1005 1339 1036 1030 1024 1180 1283 1200 1225 3207 2096 1586 1579 1479 1362 1459 1851 1643 1627 1730 1739 2001 2014 2329 2254 2326 2993 2607 2490 2408 2877 2708 2757 2977 3094 3074 3024 3269 3383 3715 3609 3436 3435 3719 5803 5204 4265 4254 3946 4934 4840 4694 4314 4814 4907 4917 4984 4951 5196 5397 5316 5220 5352 5557 5435 5452 5796 5634 9352 6372 6294 6015 5844 5834 5835 5873 6263 9301 8847 7531 6380 6677 6567 6603 7161 6942 6800 6699 6694 6784 6821 6963 7155 7053 7229 7278 8154 7968 7538 7591 7575 7928 7657 7726 7814 8119 8206 8181 8228 8734 8330 8826 8782 8983 8968 9099 9008 9081 9287 9173 9755 9692 9386 9524 9631 9567 9668 9900
500 1000
4 changes: 2 additions & 2 deletions 4.BST/TestCases/TestCase_2.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
200
3880 20 2098 376 360 103 150 309 192 257 261 285 1909 1496 652 634 450 403 474 638 645 1106 828 1059 886 846 884 933 889 899 984 1056 1041 1158 1466 1410 1390 1279 1798 1777 1697 1644 1877 1807 1997 1978 1958 1986 1984 2073 2052 2081 3088 2994 2394 2332 2319 2196 2198 2382 2462 2399 2428 2592 2580 2489 2564 2908 2895 2830 2623 2798 2749 2838 2866 2952 2985 3053 3067 3385 3126 3124 3150 3254 3282 3298 3677 3654 3498 3415 3439 8484 4204 3946 3965 3949 3971 4578 4291 4568 4472 4319 6023 5086 4680 4616 4607 4665 4932 4719 4912 4756 4983 5065 5098 5739 5117 5109 5281 5242 5135 5275 5712 5448 5326 5384 5623 5614 5609 5603 5510 5852 5749 5978 7132 6274 6117 6037 6026 6111 6249 6714 6472 6312 6305 6360 6381 6658 6649 6826 6726 6722 6851 7130 7624 7384 7272 7263 7189 7285 7620 7508 7771 7738 7665 7654 7643 7763 8346 7939 7845 8339 8278 8120 8105 8110 8280 8357 9465 9074 8847 8771 8651 8633 8986 8856 8977 9047 9357 9334 9373 9459 9881 9762 9624 9522 9467 9469 9760 9920
200
3880 20 2098 376 360 103 150 309 192 257 261 285 1909 1496 652 634 450 403 474 638 645 1106 828 1059 886 846 884 933 889 899 984 1056 1041 1158 1466 1410 1390 1279 1798 1777 1697 1644 1877 1807 1997 1978 1958 1986 1984 2073 2052 2081 3088 2994 2394 2332 2319 2196 2198 2382 2462 2399 2428 2592 2580 2489 2564 2908 2895 2830 2623 2798 2749 2838 2866 2952 2985 3053 3067 3385 3126 3124 3150 3254 3282 3298 3677 3654 3498 3415 3439 8484 4204 3946 3965 3949 3971 4578 4291 4568 4472 4319 6023 5086 4680 4616 4607 4665 4932 4719 4912 4756 4983 5065 5098 5739 5117 5109 5281 5242 5135 5275 5712 5448 5326 5384 5623 5614 5609 5603 5510 5852 5749 5978 7132 6274 6117 6037 6026 6111 6249 6714 6472 6312 6305 6360 6381 6658 6649 6826 6726 6722 6851 7130 7624 7384 7272 7263 7189 7285 7620 7508 7771 7738 7665 7654 7643 7763 8346 7939 7845 8339 8278 8120 8105 8110 8280 8357 9465 9074 8847 8771 8651 8633 8986 8856 8977 9047 9357 9334 9373 9459 9881 9762 9624 9522 9467 9469 9760 9920
9000 10000
6 changes: 3 additions & 3 deletions 4.BST/TestCases/TestCase_3.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
250
4001 2959 112 88 179 384 315 191 200 345 325 350 2648 1571 930 752 521 401 771 798 889 819 856 855 1561 1067 1186 1117 1071 1138 1122 1452 1300 1299 1270 1241 1317 1500 2494 1625 1584 2148 2056 1887 1873 1856 1783 1774 1706 1654 1758 1848 1834 1869 2055 2031 1954 2002 2143 2102 2068 2116 2263 2192 2215 2397 2273 2489 2469 2603 2512 2535 2647 2606 2630 2899 2783 2901 2905 3208 3135 3047 3042 3133 3202 3905 3498 3215 3276 3271 3427 3387 3329 3429 3430 3867 3527 3512 3504 3507 3826 3749 3693 3575 3719 3716 3738 3720 3825 3896 3878 3951 5634 5576 5295 4013 4640 4417 4091 4036 4039 4173 4136 4247 4177 4398 4296 4342 4327 4456 4429 4578 4512 4511 4573 4787 4732 4648 4694 4745 4927 4850 4797 4925 5002 5264 5032 5094 5247 5524 5518 5445 5370 5318 5337 5423 5455 5474 5566 5539 9810 5769 5667 5723 5680 6315 6005 5825 5966 5829 6145 6033 6116 6114 6183 6160 6202 6226 9460 9029 7476 7063 6997 6413 6377 6640 6493 6451 6893 6696 7260 7084 7252 7151 7194 7307 7439 7435 8317 8161 8156 7763 7863 7836 7805 8134 7970 7866 8052 7979 8141 8146 8221 8236 8231 8242 8732 8353 8661 8452 8484 8626 8706 8852 8802 8792 8841 8959 8867 9003 9369 9035 9045 9247 9160 9060 9128 9186 9214 9274 9444 9383 9646 9612 9537 9497 9749 9758 9897 9948
1100 1350
250
4001 2959 112 88 179 384 315 191 200 345 325 350 2648 1571 930 752 521 401 771 798 889 819 856 855 1561 1067 1186 1117 1071 1138 1122 1452 1300 1299 1270 1241 1317 1500 2494 1625 1584 2148 2056 1887 1873 1856 1783 1774 1706 1654 1758 1848 1834 1869 2055 2031 1954 2002 2143 2102 2068 2116 2263 2192 2215 2397 2273 2489 2469 2603 2512 2535 2647 2606 2630 2899 2783 2901 2905 3208 3135 3047 3042 3133 3202 3905 3498 3215 3276 3271 3427 3387 3329 3429 3430 3867 3527 3512 3504 3507 3826 3749 3693 3575 3719 3716 3738 3720 3825 3896 3878 3951 5634 5576 5295 4013 4640 4417 4091 4036 4039 4173 4136 4247 4177 4398 4296 4342 4327 4456 4429 4578 4512 4511 4573 4787 4732 4648 4694 4745 4927 4850 4797 4925 5002 5264 5032 5094 5247 5524 5518 5445 5370 5318 5337 5423 5455 5474 5566 5539 9810 5769 5667 5723 5680 6315 6005 5825 5966 5829 6145 6033 6116 6114 6183 6160 6202 6226 9460 9029 7476 7063 6997 6413 6377 6640 6493 6451 6893 6696 7260 7084 7252 7151 7194 7307 7439 7435 8317 8161 8156 7763 7863 7836 7805 8134 7970 7866 8052 7979 8141 8146 8221 8236 8231 8242 8732 8353 8661 8452 8484 8626 8706 8852 8802 8792 8841 8959 8867 9003 9369 9035 9045 9247 9160 9060 9128 9186 9214 9274 9444 9383 9646 9612 9537 9497 9749 9758 9897 9948
1100 1350
6 changes: 3 additions & 3 deletions 4.BST/TestCases/TestCase_4.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
300
4128 775 335 296 221 106 217 147 121 123 133 196 273 242 248 267 290 317 605 503 426 339 364 345 351 379 394 737 621 722 674 2054 1763 1265 1231 894 850 838 807 826 876 972 927 1156 1111 994 1115 1125 1179 1168 1253 1529 1354 1475 1408 1382 1373 1465 1442 1525 1584 1557 1532 1580 1570 1615 1675 1956 1776 1899 1841 1796 1861 1977 3193 2665 2515 2493 2299 2188 2132 2076 2182 2141 2191 2244 2208 2242 2240 2449 2368 2328 2408 2394 2644 2611 2594 2655 2868 2689 2725 2719 2764 2728 2838 2781 2892 3048 2895 3600 3234 3529 3410 3382 3349 3334 3241 3380 3387 3569 3919 3769 3621 3634 3650 3862 3849 3840 3784 3812 4067 4029 3992 3922 3931 3945 4011 4050 4103 6163 4209 4179 4140 4175 4199 5618 4616 4606 4228 4267 4231 4483 4381 4431 4411 4386 4542 4553 4587 5595 4848 4749 4650 4826 5494 5246 4883 5199 5016 4959 4884 5396 5302 5271 5340 5401 5425 5582 5519 5534 5697 5713 5768 5750 5974 5772 5902 5900 5918 5983 6080 6099 8771 8631 7293 6747 6718 6198 6174 6692 6328 6253 6319 6582 6472 6438 6346 6569 6624 6604 6691 6930 6800 6767 6834 7147 7105 7260 7158 7148 7205 7261 7278 7288 7423 7390 7358 8434 8032 7545 7520 7502 7495 7488 7836 7571 7717 7871 7848 7857 7888 7925 7935 8166 8136 8095 8055 8301 8252 8256 8420 8312 8398 8462 8489 8465 8609 8598 8769 8687 8649 8683 8758 8746 8821 8795 8931 8883 8900 8888 9295 9078 9017 8973 9005 9038 9047 9076 9215 9105 9095 9129 9135 9285 9267 9230 9279 9980 9830 9474 9416 9775 9551 9523 9512 9732 9571 9828 9853 9834
6000 6300
300
4128 775 335 296 221 106 217 147 121 123 133 196 273 242 248 267 290 317 605 503 426 339 364 345 351 379 394 737 621 722 674 2054 1763 1265 1231 894 850 838 807 826 876 972 927 1156 1111 994 1115 1125 1179 1168 1253 1529 1354 1475 1408 1382 1373 1465 1442 1525 1584 1557 1532 1580 1570 1615 1675 1956 1776 1899 1841 1796 1861 1977 3193 2665 2515 2493 2299 2188 2132 2076 2182 2141 2191 2244 2208 2242 2240 2449 2368 2328 2408 2394 2644 2611 2594 2655 2868 2689 2725 2719 2764 2728 2838 2781 2892 3048 2895 3600 3234 3529 3410 3382 3349 3334 3241 3380 3387 3569 3919 3769 3621 3634 3650 3862 3849 3840 3784 3812 4067 4029 3992 3922 3931 3945 4011 4050 4103 6163 4209 4179 4140 4175 4199 5618 4616 4606 4228 4267 4231 4483 4381 4431 4411 4386 4542 4553 4587 5595 4848 4749 4650 4826 5494 5246 4883 5199 5016 4959 4884 5396 5302 5271 5340 5401 5425 5582 5519 5534 5697 5713 5768 5750 5974 5772 5902 5900 5918 5983 6080 6099 8771 8631 7293 6747 6718 6198 6174 6692 6328 6253 6319 6582 6472 6438 6346 6569 6624 6604 6691 6930 6800 6767 6834 7147 7105 7260 7158 7148 7205 7261 7278 7288 7423 7390 7358 8434 8032 7545 7520 7502 7495 7488 7836 7571 7717 7871 7848 7857 7888 7925 7935 8166 8136 8095 8055 8301 8252 8256 8420 8312 8398 8462 8489 8465 8609 8598 8769 8687 8649 8683 8758 8746 8821 8795 8931 8883 8900 8888 9295 9078 9017 8973 9005 9038 9047 9076 9215 9105 9095 9129 9135 9285 9267 9230 9279 9980 9830 9474 9416 9775 9551 9523 9512 9732 9571 9828 9853 9834
6000 6300
48 changes: 24 additions & 24 deletions 5.Heap-PriorityQ/TestCases_Que1.txt
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
Input 1:
iitguwahati
Output 1:
itiaitaguwh (this is one possible output, if you print any other which follows Bob's rearrangement, then it is acceptable)
Input 2:
aaaaabbbbbccccc
Ouput 2:
abcabcabcabcabc (this is one possible output, if you print any other which follows Bob's rearrangement, then it is acceptable)
Input 3:
geeksforgeeks
Output 3:
egekesegksfor (this is one possible output, if you print any other which follows Bob's rearrangement, then it is acceptable)
Input 4:
aaaaaabbbbbbbb
Ouput 4:
Not Possible
Input 1:
iitguwahati

Output 1:
itiaitaguwh (this is one possible output, if you print any other which follows Bob's rearrangement, then it is acceptable)

Input 2:
aaaaabbbbbccccc

Ouput 2:
abcabcabcabcabc (this is one possible output, if you print any other which follows Bob's rearrangement, then it is acceptable)

Input 3:
geeksforgeeks

Output 3:
egekesegksfor (this is one possible output, if you print any other which follows Bob's rearrangement, then it is acceptable)

Input 4:
aaaaaabbbbbbbb

Ouput 4:
Not Possible

Loading