Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace Largest_Common_End
- {
- class Largest_Common_End
- {
- static void Main(string[] args)
- {
- string[] firstArray = Console.ReadLine().Split(' ').ToArray();
- string[] secondArray = Console.ReadLine().Split(' ').ToArray();
- int output = LargestCommonEnd(firstArray, secondArray);
- Console.WriteLine(output);
- }
- static int LargestCommonEnd(string[] firstArray, string[] secondArray)
- {
- var leftCount = 0;
- var rightCount = 0;
- while ((leftCount < firstArray.Length && leftCount < secondArray.Length) &&
- (rightCount < firstArray.Length && rightCount < secondArray.Length))
- {
- if (firstArray[leftCount] == secondArray[leftCount]) leftCount++;
- else if (firstArray[firstArray.Length - rightCount - 1] == secondArray[secondArray.Length - rightCount - 1]) rightCount++;
- else break;
- }
- if (leftCount < rightCount) return rightCount;
- else return leftCount;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement