@Test public void shouldReturnZeroIfTheArrayIsEmptyIterative() { int[] array = { }; int sequenceLength = lcs.findIterative(array); assertEquals(0, sequenceLength); }
public int findIterative(int[] numbers) { validateInput(numbers); if (numbers.length == 0) { return 0; } boolean consecutiveSequenceFound = false; int result = 0; int start = 0, end = 0; for (int i = 1; i < numbers.length; i++) { if (numbers[i - 1] < numbers[i]) { end = i; } else { start = i; } if (end - start > result) { consecutiveSequenceFound = true; result = end - start; } } if (consecutiveSequenceFound) { return result + 1; } else { return result; } }
FindLongestConsecutiveSequence { public int findIterative(int[] numbers) { validateInput(numbers); if (numbers.length == 0) { return 0; } boolean consecutiveSequenceFound = false; int result = 0; int start = 0, end = 0; for (int i = 1; i < numbers.length; i++) { if (numbers[i - 1] < numbers[i]) { end = i; } else { start = i; } if (end - start > result) { consecutiveSequenceFound = true; result = end - start; } } if (consecutiveSequenceFound) { return result + 1; } else { return result; } } }
FindLongestConsecutiveSequence { public int findIterative(int[] numbers) { validateInput(numbers); if (numbers.length == 0) { return 0; } boolean consecutiveSequenceFound = false; int result = 0; int start = 0, end = 0; for (int i = 1; i < numbers.length; i++) { if (numbers[i - 1] < numbers[i]) { end = i; } else { start = i; } if (end - start > result) { consecutiveSequenceFound = true; result = end - start; } } if (consecutiveSequenceFound) { return result + 1; } else { return result; } }  }
FindLongestConsecutiveSequence { public int findIterative(int[] numbers) { validateInput(numbers); if (numbers.length == 0) { return 0; } boolean consecutiveSequenceFound = false; int result = 0; int start = 0, end = 0; for (int i = 1; i < numbers.length; i++) { if (numbers[i - 1] < numbers[i]) { end = i; } else { start = i; } if (end - start > result) { consecutiveSequenceFound = true; result = end - start; } } if (consecutiveSequenceFound) { return result + 1; } else { return result; } }  int findIterative(int[] numbers); int findRecursive(int[] array); }
FindLongestConsecutiveSequence { public int findIterative(int[] numbers) { validateInput(numbers); if (numbers.length == 0) { return 0; } boolean consecutiveSequenceFound = false; int result = 0; int start = 0, end = 0; for (int i = 1; i < numbers.length; i++) { if (numbers[i - 1] < numbers[i]) { end = i; } else { start = i; } if (end - start > result) { consecutiveSequenceFound = true; result = end - start; } } if (consecutiveSequenceFound) { return result + 1; } else { return result; } }  int findIterative(int[] numbers); int findRecursive(int[] array);  }