Geeksforgeeks

Timer is Running

You are given a sorted array containing only numbers 0 and 1. Find the transition point efficiently. The transition point is a point where "0" ends and "1" begins (0 based indexing).

Note that, if there is no "1" exists, print -1.

Note that, in case of all 1s print 0.

**Example 1:**

**Input:
**N = 5
C[] = {0,0,0,1,1}
**Output: **3**
Explanation: **position 3 is 0 and next
one is 1, so answer is 3.

**Example 2:**

**Input:
**N = 4
C[] = {0,0,0,0}
**Output: **-1**
Explanation: **Since, there is no "1",so
the answer is -1.

**Your Task:**

The task is to complete the function **transitionPoint**() that takes array and N as input and returns the value of the position where "0" ends and "1" begins.

**Expected Time Complexity:** O(LogN).

**Expected Auxiliary Space:** O(1).

**Constraints:**

1 ≤ N ≤ 500000

0 ≤ C[i] ≤ 1

Author: rajatjha

If you have purchased any course from GeeksforGeeks then please ask your doubt on course discussion forum. You will get quick replies from GFG Moderators there.

jainshubham52535 | 529 |

Pathak1899 | 436 |

yashdip123 | 380 |

kirtidee18 | 377 |

jots62 | 351 |

kirtidee18 | 1057 |

ykaushik | 752 |

aggarwalvatsal5 | 741 |

harbilassingh | 576 |

pmr_3689 | 570 |

blackshadows | 5456 |

Ibrahim Nash | 5450 |

akhayrutdinov | 5111 |

mb1973 | 4976 |

Quandray | 4827 |

Login to report an issue on this page.