Тёмный

3209. Number of Subarrays With AND Value of K (Leetcode Hard) 

Programming Live with Larry
Подписаться 33 тыс.
Просмотров 471
50% 1

Larry solves and analyzes this Leetcode problem as both an interviewer and an interviewee. This is a live recording of a real engineer solving a problem live - no cuts or edits!
Problem: leetcode.com/p...
Twitch: / larryny
Discord: / discord
Instagram: / larrysomewhere
#leetcode #coding #programming

Опубликовано:

 

16 окт 2024

Поделиться:

Ссылка:

Скачать:

Готовим ссылку...

Добавить в:

Мой плейлист
Посмотреть позже
Комментарии : 7   
@Algorithmist
@Algorithmist 3 месяца назад
Were you able to get through the subarrays?
@RichyRich18
@RichyRich18 3 месяца назад
Hey Larry, I'm new to LeetCode and have been learning and growing by watching your videos. They are really good compared to others on RU-vid . i appreciate your approaches they are really good and are commendable. I need some help understanding approaches better. I often spend a lot of time trying to grasp them. For example, I still feel that your solution will take O(n^2), but you mentioned it would take O(32*n). I implemented the same logic as yours using two for loops i know its O(n^2): class Solution { public: long long countSubarrays(vector& nums, int k) { int ad = INT_MAX; int n = nums.size(); long long total = 0; |for (int i = 0; i < n; i++) { | long long cnt = 0; | ad = INT_MAX; | |for (int j = i; j < n; j++) { | | ad &= nums[j]; | | if (ad < k) break; | | if (ad == k) { | | cnt++; | | } | |} | total += cnt; |} |return total; } }; But it gives TLE, while yours does not. the only suggestion is that, if you could give some more time to explain the logic behind your approaches, it will be grate help for me and others. Thank you Love from India🫡
@Algorithmist
@Algorithmist 2 месяца назад
Try the discord - it is easier to get feedback there!
@Parth-y8o
@Parth-y8o 3 месяца назад
Great Solution Larry! What was the previous problem that you were talking about in the video, that helped you solve this?
@Algorithmist
@Algorithmist 3 месяца назад
It was this one - leetcode.com/problems/find-subarray-with-bitwise-or-closest-to-k/
@Lakshya-f4l
@Lakshya-f4l 3 месяца назад
Thanks!
@VarshilNarola
@VarshilNarola 3 месяца назад
I was too dumb to think about dp had done it in n*logn*32 time using binary search and was able to submit in java but failed in cpp. don't know why leetcode is weird!!
Далее
ITZY "GOLD" M/V
03:20
Просмотров 7 млн
Making an Algorithm Faster
30:08
Просмотров 121 тыс.
Stop using std::vector wrong
23:14
Просмотров 111 тыс.
leetcode 552 Student Attendance Record II
9:55
Просмотров 1,1 тыс.
I Solved 100 LeetCode Problems
13:11
Просмотров 115 тыс.
Viral Video of a Man's Crazy Job Interview
16:02
Просмотров 1,4 млн
I'm Ditching Try/Catch for Good!
10:29
Просмотров 71 тыс.
ITZY "GOLD" M/V
03:20
Просмотров 7 млн