Category : dynamic

I have a program that has a vector. The vector takes pointers to an object which I dynamically create in my program. I then wish to delete these dynamic objects from the vector. For example: int main() { vector<Account*> allAccounts; Account* a1 = new Savings(0, "Savings"); Account* a2 = new Current(0, "Current"); allAccounts.push_back(a1); allAccounts.push_back(a2); for ..

Read more

The compiler shows TLE . can you help me figure it out. Why it shows TLE? you can find the problem at https://leetcode.com/problems/house-robber/ class Solution { public: int rob(vector<int>& arr) { int n=arr.size(); // y=1st alternate prefix sum array x= 2nd alternate prefix sum array int x,y; x=0; y=0; for(int i=1;i<n;i+2) { x+=arr[i]; y+=arr[i-1]; } ..

Read more