File tree Expand file tree Collapse file tree 3 files changed +48
-0
lines changed
problem_3014_minimum_number_of_pushes_to_type_word_i Expand file tree Collapse file tree 3 files changed +48
-0
lines changed Original file line number Diff line number Diff line change @@ -2047,6 +2047,7 @@ pub mod problem_3005_count_elements_with_maximum_frequency;
2047
2047
pub mod problem_3010_divide_an_array_into_subarrays_with_minimum_cost_i;
2048
2048
pub mod problem_3011_find_if_array_can_be_sorted;
2049
2049
pub mod problem_3012_minimize_length_of_array_using_operations;
2050
+ pub mod problem_3014_minimum_number_of_pushes_to_type_word_i;
2050
2051
2051
2052
#[ cfg( test) ]
2052
2053
mod test_utilities;
Original file line number Diff line number Diff line change
1
+ pub struct Solution ;
2
+
3
+ // ------------------------------------------------------ snip ------------------------------------------------------ //
4
+
5
+ impl Solution {
6
+ pub fn minimum_pushes ( word : String ) -> i32 {
7
+ let n = word. len ( ) ;
8
+ let quotient = n / 8 ;
9
+ let remainder = n % 8 ;
10
+
11
+ ( 4 * ( 1 + quotient) * quotient + ( quotient + 1 ) * remainder) as _
12
+ }
13
+ }
14
+
15
+ // ------------------------------------------------------ snip ------------------------------------------------------ //
16
+
17
+ impl super :: Solution for Solution {
18
+ fn minimum_pushes ( word : String ) -> i32 {
19
+ Self :: minimum_pushes ( word)
20
+ }
21
+ }
22
+
23
+ #[ cfg( test) ]
24
+ mod tests {
25
+ #[ test]
26
+ fn test_solution ( ) {
27
+ super :: super :: tests:: run :: < super :: Solution > ( ) ;
28
+ }
29
+ }
Original file line number Diff line number Diff line change
1
+ pub mod greedy;
2
+
3
+ pub trait Solution {
4
+ fn minimum_pushes ( word : String ) -> i32 ;
5
+ }
6
+
7
+ #[ cfg( test) ]
8
+ mod tests {
9
+ use super :: Solution ;
10
+
11
+ pub fn run < S : Solution > ( ) {
12
+ let test_cases = [ ( "abcde" , 5 ) , ( "xycdefghij" , 12 ) ] ;
13
+
14
+ for ( word, expected) in test_cases {
15
+ assert_eq ! ( S :: minimum_pushes( word. to_string( ) ) , expected) ;
16
+ }
17
+ }
18
+ }
You can’t perform that action at this time.
0 commit comments