и посмотреть медиа
PHP | LeetCode - Tests and Security
и посмотреть медиа
Resource with LeetCode PHP tests, interview questions and vacancies. Ideal for preparing for work as a developer.
Resource with LeetCode PHP tests, interview questions and vacancies. Ideal for preparing for work as a developer.
AI bot for text-to-speech and voice cloning in Telegram. Create audio using neural network quickly and easily.
This Telegram resource is dedicated to preparing for PHP interviews using LeetCode tasks. Here are the latest tests that will help you master key algorithms and data structures in PHP.👨💻The section with interview questions contains typical tasks that are asked in the interviewIT-companies. Users will find solution parsings, code examples and optimization tips. This is a great way to practice before a real interview.📚In addition, vacancies for PHP developers are published. The resource helps not only to learn, but also to find work in the field of web development. Regular updates provide fresh content for all levels—fromjuniorbeforesenior.
Задача: 1094. Car Pooling Сложность: medium Есть автомобиль с пустыми сиденьями емкостью capacity. Автомобиль движется только на восток (то есть он не может повернуть и ехать на запад). Дан целочисленный параметр capacity и массив поездок trips, где trips[i] = [numPassengersi, fromi, toi] указывает, что на i-й поездке numPassengersi пассажиров должны быть забраны на позиции fromi и высажены на позиции toi. Позиции заданы как количество километров на восток от начальной точки автомобиля. Верните true, если возможно забрать и высадить всех пассажиров для всех указанных поездок, или false в противном случае. Пример: Input: trips = [[2,1,5],[3,3,7]], capacity = 4 Output: false 👨💻 Алгоритм: 1⃣Простая идея заключается в том, чтобы пройти от начала до конца и проверить, превышает ли фактическая вместимость capacity. 2⃣Чтобы узнать фактическую вместимость, нужно просто знать изменение количества пассажиров в каждый момент времени. 3⃣Мы можем сохранить изменения количества пассажиров в каждый момент времени, отсортировать их по меткам времени и, наконец, пройтись по ним, чтобы проверить фактическую вместимость. 😎 Решение: class Solution { function carPooling($trips, $capacity) { $timestamp = []; foreach ($trips as $trip) { $timestamp[$trip[1]] = ($timestamp[$trip[1]] ?? 0) + $trip[0]; $timestamp[$trip[2]] = ($timestamp[$trip[2]] ?? 0) - $trip[0]; } ksort($timestamp); $usedCapacity = 0; foreach ($timestamp as $change) { $usedCapacity += $change; if ($usedCapacity > $capacity) { return false; } } return true; } } Ставь 👍 и забирай 📚 Базу знаний
Открыть канал и посмотреть медиаOnly registered users can share their opinion.
Be the first to share your impression of this resource!