<repo_name>evanJensengit/problems<file_sep>/interviewProblems/main.cpp
//
//  main.cpp
//  interviewProblems
//
//  Created by <NAME> on 8/22/20.
//  Copyright © 2020 <NAME>. All rights reserved.
//

#include <iostream>
#include "problems.h"
using namespace std;

int main() {
   // insert code here...
   problems a;
   int num = 2147;
   int reversedNum = a.reverse(num);
  // cout << reverse(num) << endl;
   cout << reversedNum << endl;
   
   int num2 = 2147;
   int b = num2 % 10;
//cout << b << endl;
   
   
}
<file_sep>/README.md
# problems
practice problems 
<file_sep>/reverseInt.cpp
int problems::reverse (int num) {
   if (num > 2147483648 || num < -2147483648 ) {
      return 0;
   }
   string reversed = "";
   int div = 10;
   int oneDigitLess, numAtEnd;
   bool isNegative = false;
   if (num < 0) {
      isNegative = true;
   }
   
   for (int i = 0; i < 10; i++) {
      oneDigitLess = num / div;
      numAtEnd = num % div;
      num = oneDigitLess;
      if (isNegative && i < 1) {
         numAtEnd *= -1;
         num *= -1;
      }
      cout << num << endl;
      reversed += to_string(numAtEnd);
      if (oneDigitLess == 0) {
         break;
      }
   }
   cout << reversed << endl;
   bool isNonZero = false;
   int length = reversed.length();
   for (int i = 0; i< length; i++) {
     // cout << reversed << endl;
      if (!isNonZero) {
         if (reversed.at(i) == '0') {
            reversed.erase(0, 1);
            i--;
            length--;
         }
         else
            isNonZero = true;
      }
   }
   
   try {
      num = stoi(reversed);
   }
   catch (const exception& e) {
      cout << "exception caught " << e.what() << endl;
      return 0;
   }
   if (isNegative) {
      num *= -1;
   }
   //cout << num << endl;
   return num;
   }
   <file_sep>/twoSum.cpp
//
//  main.cpp
//  TwoSumProblem
//
//  Created by <NAME> on 8/5/20.
//  Copyright © 2020 <NAME>. All rights reserved.
//
using namespace std;
#include <iostream>
#include <vector>

vector<int> twoSum(vector<int>& nums, int target) {
      bool solutionNotFound = true;
      int indexBase = 0;
      int baseAndCurrentSum;
      int currentElement;
      int currentElementBase;
      while (solutionNotFound) {
         
         for (int i = indexBase; i < nums.size(); i++) {
            baseAndCurrentSum = nums[i] + nums[indexBase];
            //cout << baseAndCurrentSum << endl;
            if (baseAndCurrentSum == target) {
               solutionNotFound = false;
               currentElementBase = nums[indexBase];
               currentElement = nums[i];
               nums.erase(nums.begin(), nums.end());
               nums.push_back (currentElement);
               nums.push_back (currentElementBase);
               break;
            }
            
         }
         if (indexBase == nums.size()) {
            break;
         }
         indexBase++;
         
      }
      return nums;
}


int main(int argc, const char * argv[]) {
   vector<int> myInts {12, 14, 22, 7, 8, 13 };
   for (auto i = myInts.begin(); i != myInts.end(); ++i) {
      cout << *i << endl;
   }
   int target = 21;
   myInts = twoSum(myInts, target);
   cout << "New vector after twoSum: " << endl;

   for (auto i = myInts.begin(); i != myInts.end(); ++i) {
      cout << *i << endl;
   }
  // cout << myInts.size();
//   for (int i = 0; i <= 20; i++) {
//      myInts.push_back(i);
//      }
//   for (int i = 0; i <= 20; i++) {
//      cout << myInts[i] << endl;
//   }
   
   
}
<file_sep>/interviewProblems/problems.h
//
//  reverseInteger.hpp
//  interviewProblems
//
//  Created by <NAME> on 8/22/20.
//  Copyright © 2020 <NAME>. All rights reserved.
//

#ifndef problems_h
#define problems_h
using namespace std;
#include <iostream>
#include<string>
#include <stdio.h>
#include <vector>
class problems {
public: 
   void start();
   int reverse (int);

};
#endif /* reverseInteger_hpp */
<file_sep>/interviewProblems/problems.cpp
//
//  reverseInteger.cpp
//  interviewProblems
//
//  Created by <NAME> on 8/22/20.
//  Copyright © 2020 <NAME>. All rights reserved.
//

#include "problems.h"
   
int problems::reverse (int num) {
   string reversed = "";
   int div = 10;
   int oneDigitLess, numAtEnd;
   bool isNegative = false;
   if (num < 0) {
      isNegative = true;
      num *= -1;
   }
   
   for (int i = 0; i < 10; i++) {
      oneDigitLess = num / div;
      numAtEnd = num % div;
      num = oneDigitLess;
     // cout << num << endl;
      reversed += to_string(numAtEnd);
      if (oneDigitLess == 0 ) {
         break;
      }
   }
   bool isNonZero = false;
   int length = reversed.length();
   for (int i = 0; i< length; i++) {
     // cout << reversed << endl;
      if (!isNonZero) {
         if (reversed.at(i) == '0') {
            reversed.erase(0, 1);
            i--;
            length--;
         }
         else
            isNonZero = true;
      }
   }
   num = stoi(reversed);
   if (isNegative) {
      num *= -1;
   }
   //cout << num << endl;
   return num;
   }
   

