kunal-kushwaha / DSA-Bootcamp-Java

This repository consists of the code samples, assignments, and notes for the Java data structures & algorithms + interview preparation bootcamp of WeMakeDevs.
https://www.youtube.com/playlist?list=PL9gnSGHSqcnr_DxHsP7AW9ftq0AtAyYqJ
17.24k stars 11.07k forks source link

First and last element code using Js #1096

Closed omkarpatole1799 closed 1 year ago

omkarpatole1799 commented 1 year ago

I have tried the brute force appraoch (i.e. running the loop from start upto target and end upto target). Actually this bruteforce approach is much efficient than the binary search approach. The bruteforce approach takes 55 ms to run and consumes 42.2 MB of ram, while The binarysearch approach takes 73 ms to run and consumes 44.6 MB of ram I have added few screenshots which shows the same please check it.

for binary search approach image

for bruteforce approach image