fork download
  1. #include <unordered_map>
  2. #include<vector>
  3. using namespace std;
  4. vector<int> longestConsecutiveIncreasingSequence(int *arr, int n){
  5. unordered_map <int, bool> visitedElements ;
  6. unordered_map <int, int> elementToIndexMapping;
  7. for(int i = 0; i < n; i++){
  8. elementToIndexMapping[arr[i]] = i;
  9. if(visitedElements.count(arr[i]) == 0){
  10. visitedElements[arr[i]] = true;
  11. }
  12. }
  13. vector<int> longestSequence;
  14. int globalMaxSequenceLength = 1;
  15. int globalMinStartIndex = 0;
  16. for(int i = 0; i < n; i++){
  17. int num = arr[i];
  18. int currentMinStartIndex = i;
  19. int count = 0;
  20. int tempNum = num;
  21. //Forward
  22. while(visitedElements.count(tempNum) == 1 && visitedElements[tempNum] == true){
  23. visitedElements[tempNum] = false;
  24. count++;
  25. tempNum++;
  26. }
  27. //Backward
  28. tempNum = num-1;
  29. while(visitedElements.count(tempNum) == 1 && visitedElements[tempNum] == true){
  30. visitedElements[tempNum] = false;
  31. count++;
  32. currentMinStartIndex = elementToIndexMapping[tempNum];
  33. tempNum--;
  34. }
  35. if(count > globalMaxSequenceLength){
  36. globalMaxSequenceLength = count;
  37. globalMinStartIndex = currentMinStartIndex;
  38. } else if(count == globalMaxSequenceLength) {
  39. if(currentMinStartIndex < globalMinStartIndex) {
  40. globalMinStartIndex = currentMinStartIndex;
  41. }
  42. }
  43. }
  44. int globalStartNum = arr[globalMinStartIndex];
  45. longestSequence.push_back(globalStartNum);
  46. globalMaxSequenceLength--;
  47. while(globalMaxSequenceLength != 0){
  48. globalStartNum++;
  49.  
  50. longestSequence.push_back(globalStartNum);
  51. globalMaxSequenceLength--;
  52. }
  53. return longestSequence;
  54. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
/usr/bin/ld: /usr/lib/gcc/x86_64-linux-gnu/8/../../../x86_64-linux-gnu/Scrt1.o: in function `_start':
(.text+0x20): undefined reference to `main'
collect2: error: ld returned 1 exit status
stdout
Standard output is empty