Cảm thấy luyện thuật toán nhưng như kiểu học vẹt?

You are given two arrays of integers nums1 and nums2, possibly of different lengths. The values in the arrays are between 1 and 6, inclusive.

In one operation, you can change any integer's value in any of the arrays to any value between 1 and 6, inclusive.

Return the minimum number of operations required to make the sum of values in nums1 equal to the sum of values in nums2. Return -1 if it is not possible to make the sum of the two arrays equal.
Example
Input: nums1 = [1,2,3,4,5,6], nums2 = [1,1,2,2,2,2]
Output: 3
Explanation: You can make the sums of nums1 and nums2 equal with 3 operations. All indices are 0-indexed.
  • Change nums2[0] to 6. nums1 = [1,2,3,4,5,6], nums2 = [6,1,2,2,2,2].
  • Change nums1[5] to 1. nums1 = [1,2,3,4,5,1], nums2 = [6,1,2,2,2,2].
  • Change nums1[2] to 2. nums1 = [1,2,2,4,5,1], nums2 = [6,1,2,2,2,2].

Gỉai thử nào mấy fen ( làm biếng dịch quá ) :V
 
You are given two arrays of integers nums1 and nums2, possibly of different lengths. The values in the arrays are between 1 and 6, inclusive.

In one operation, you can change any integer's value in any of the arrays to any value between 1 and 6, inclusive.

Return the minimum number of operations required to make the sum of values in nums1 equal to the sum of values in nums2. Return -1 if it is not possible to make the sum of the two arrays equal.
Example
Input: nums1 = [1,2,3,4,5,6], nums2 = [1,1,2,2,2,2]
Output: 3
Explanation: You can make the sums of nums1 and nums2 equal with 3 operations. All indices are 0-indexed.
  • Change nums2[0] to 6. nums1 = [1,2,3,4,5,6], nums2 = [6,1,2,2,2,2].
  • Change nums1[5] to 1. nums1 = [1,2,3,4,5,1], nums2 = [6,1,2,2,2,2].
  • Change nums1[2] to 2. nums1 = [1,2,2,4,5,1], nums2 = [6,1,2,2,2,2].

Gỉai thử nào mấy fen ( làm biếng dịch quá ) :V
kho vai
 
hehe, bạn học vẹt 10 bài thì dễ, chứ thử 500 bài xem :)
Bạn mà học vẹt dc 500 bài cũng là giỏi lắm rồi đấy. 500 bài medium/hard trên leetcode nhé.
Chuẩn để vô FANG đó.
 
mấy thánh thích nổ bài :V
chẳng qua tui chưa học quy hoahcj động thui fen
hsWKZZj.gif
 
Thím như tôi kỳ vừa rồi, ọc môn này chả biết gì. Cũng có luyện, nhưng mà gặp vấn đề mới thì chết cứng. Tđn trước ngày thì ôn tủ tầm chục bài thì trúng mẹ 4 bài ăn ngay con A+ :beauty:
 
You are given two arrays of integers nums1 and nums2, possibly of different lengths. The values in the arrays are between 1 and 6, inclusive.

In one operation, you can change any integer's value in any of the arrays to any value between 1 and 6, inclusive.

Return the minimum number of operations required to make the sum of values in nums1 equal to the sum of values in nums2. Return -1 if it is not possible to make the sum of the two arrays equal.
Example
Input: nums1 = [1,2,3,4,5,6], nums2 = [1,1,2,2,2,2]
Output: 3
Explanation: You can make the sums of nums1 and nums2 equal with 3 operations. All indices are 0-indexed.
  • Change nums2[0] to 6. nums1 = [1,2,3,4,5,6], nums2 = [6,1,2,2,2,2].
  • Change nums1[5] to 1. nums1 = [1,2,3,4,5,1], nums2 = [6,1,2,2,2,2].
  • Change nums1[2] to 2. nums1 = [1,2,2,4,5,1], nums2 = [6,1,2,2,2,2].

Gỉai thử nào mấy fen ( làm biếng dịch quá ) :V
Lại này
sum 2 mảng rồi trừ lấy distance.
sort 2 mảng
mảng lớn hơn thì start từ max (gọi là mảng A), mảng nhỏ hơn start từ min (gọi là mảng B)
mỗi step giảm distance đi : min(max(A - 1, 6 - B), distance), nếu số này = 0 mà distance vẫn > 0 thì -1

lấy ở mảng naof thì nhích con trỏ ở mảng ấy để loại bỏ phân tử ấy đi.
 
code white board đi thím, ko chơi pseudo code :LOL: từ ý tưởng tới implement là cả vấn đề đó
 
3 cái này giống nhau mà. Khó nhất là tìm công thức recursion, ra công thức rồi thì chuyển sang DP chút xíu. Traverse Graph thì cũng dùng 2 cái trên.

Thời đại thợ code outsource sinh ra toàn những ông còn không biết algo để làm gì là hiểu ngành IT nó thiếu nhân lực thế nào rồi.
cái dp sao mà giống đệ quy được hả thím, dp = đệ quy + công thức bài toán con + điều kiện. Mà cái tìm công thức thì nó chả dễ gì như đệ quy cả, khác biệt hoàn toàn,
 
cái dp sao mà giống đệ quy được hả thím, dp = đệ quy + công thức bài toán con + điều kiện. Mà cái tìm công thức thì nó chả dễ gì như đệ quy cả, khác biệt hoàn toàn,

Thím xem thử video này của 1 thằng làm ở google


Bài toán con của dp chính là công thức recursion, còn caid điều kiện ban đầu thì quá dễ rồi
 
theo ý kiến cá nhân, làm đc hết tất cả đề easy trên leetcode vs hackerrank là khá đủ tư duy cho 90% yêu cầu công việc lập trình tại việt nam rồi, làm đc cả medium nữa là 99% còn hardest là kiểu dành cho mấy thằng làm ở fb,google ...các kiểu :D

ps nhiều bài easy mà khó vl : )))
 
Mình luyện thuật toán trên leetcode thì bị vấn đề như sau:

Đối với những dạng, mẫu nào đã từng giải rồi thì mình làm rất nhanh, kiểu miễn là đã làm rồi thì ok. Còn dạng mới đa số không giải được hoặc chật vật vcl các thím ạ :(

Mình mới luyện được 1 tháng mà cảm thấy không lên ý :*(
thím code bằng ngôn ngữ gì? em code bằng C thì thấy nhiều bài thuật toán dễ mà cái phần khai báo input khoai vc
 
Back
Top