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;
20472047pub mod problem_3010_divide_an_array_into_subarrays_with_minimum_cost_i;
20482048pub mod problem_3011_find_if_array_can_be_sorted;
20492049pub mod problem_3012_minimize_length_of_array_using_operations;
2050+ pub mod problem_3014_minimum_number_of_pushes_to_type_word_i;
20502051
20512052#[ cfg( test) ]
20522053mod 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