two pointers alogorithm

A collection of 8 post

Find All Anagrams (Hash, Two-Pointer, Sliding Window)

Problem Write a program that counts the number of substrings of S that are anagrams and T strings in S string. When identifying anagrams, case is sensitive. Substrings must be contiguous strings. input The first S string is entered on the first line, and the T string is entered on the second line…

Anagram (Hash)

Problem Anagrams Two words are said to be anagrams when two strings differ in alphabetical order, but their composition matches. For example, AbaAeCe and baeeACA have different alphabets, but if you look at their composition, they are A(2), a(1), b(1), C(1), e(2), the alphabets and their numbers…

Class President (Hash)

Problem A, B, C, D, and E candidates registered as candidates to select the class president. The ballot is written with the symbol (alphabetically) of the candidate chosen by the students in the class, and the teacher announces the symbol. After the teacher’s presentation, write a program that…

Maximum Sales

Problem Hyun-soo’s father runs a bakery. Hyeon-soo’s father gave him the sales record for N days and told him to find the maximum sales for K consecutive days. If N=10, the sales record for 10 days is as follows. In this case, if K = 3 The maximum sales for 3 consecutive days is 11+20+25=560,000 won…

Consecutive Sub Sequence 2

Problem You are given a sequence of N numbers. Write a program to find how many times in this sequence the sum of consecutive subsequences is less than or equal to a specific number M. If N=5, M=5 and the sequence is A continuous subsequence whose sum is 5 or less is {1}, {3}, {1}, {2}, {3}, {1,…

Consecutive Sub Sequence

Problem You are given a sequence of N numbers. Write a program to count how many times in this sequence the sum of consecutive subsequences is a specific number M. If N=8, M=6 and the sequence is There are three consecutive subsequences whose sum is 6: {2, 1, 3}, {1, 3, 1, 1}, and {3, 1, 1,…

Finding Commons

Problem Given two sets A and B, write a program that extracts the common elements of the two sets and outputs them in ascending order. input The first line gives the size N of set A (1<=N<=30,000). The second line gives N elements. Duplicate elements are not given. The third line gives the size M of…

Concatenate Two Arrays

Problem Given two arrays sorted in ascending order, write a program that merges the two arrays in ascending order and prints them. input The first line gives the size N (1<=N<=100) of the first array. The second line gives the N array elements in ascending order. The third line gives the size M (…