BVP-ISTE / Hacktober2022

MIT License
4 stars 64 forks source link

C++ Solution #326

Closed Ivan2001otp closed 11 months ago

Ivan2001otp commented 11 months ago

APPROACH

  1. I have used two Pointer approach to solve this problem.
  2. Initially the first pointer will point to second element of vector, and traverses till last second element of vector.
  3. I will create a pointer immediate previous to the first pointer , now I will check whether the elements of previous pointer and current-pointer are different & element pointed by current pointer and immediate next element is different .
  4. If this condition satisfies then , I will add the element into the variable and return boolean value specifying that the unique element exists or not.
  5. Further I have added two conditions to handle , what if first element or last element of vector is unique.
  6. In any case , if the unique Element does not exist then I have printed the verdict in console.

OUTPUT

Driver_function_MainMethod

find_Unique_Element_Function

input_array1

output_for_array1

input_array2

arr2_output

Ivan2001otp commented 11 months ago

APPROACH

  1. I have used two Pointer approach to solve this problem.
  2. Initially the first pointer will point to second element of vector, and traverses till last second element of vector.
  3. I will create a pointer immediate previous to the first pointer , now I will check whether the elements of previous pointer and current-pointer are different & element pointed by current pointer and immediate next element is different .
  4. If this condition satisfies then , I will add the element into the variable and return boolean value specifying that the unique element exists or not.
  5. Further I have added two conditions to handle , what if first element or last element of vector is unique.
  6. In any case , if the unique Element does not exist then I have printed the verdict in console.

OUTPUT

  • Driver Program

Driver_function_MainMethod

  • Util Function

find_Unique_Element_Function

  • Input & output results

input_array1

output_for_array1

input_array2

arr2_output