KaTiWarn's blog

By KaTiWarn, history, 2 months ago, In English

Does anyone face problem like me? I found that when I tried to write two pointer, I am very confused and I struggle with my code for very long time. Sometimes, I easily bugged. How can I improve this?

 
 
 
 
  • Vote: I like it
  • +9
  • Vote: I do not like it

»
2 months ago, # |
  Vote: I like it +1 Vote: I do not like it

You need to understand monotonocity. Why are we skipping items? Because they are going to be worse than what we are going to get. Easy peasy. When we have rotten apples, you throw them away.

»
2 months ago, # |
Rev. 3   Vote: I like it 0 Vote: I do not like it

Excuse me.I am a newbie and may I ask you for what the difference between pointers and variables is?

Sorry,my English may not be very good :(

  • »
    »
    2 months ago, # ^ |
    Rev. 2   Vote: I like it 0 Vote: I do not like it

    Actually pointer is a variable .

    Other variables store data like int, long long, short , char...... , also pointer is a variable which stores address .

    But what KaTiWarn asks about is a technique not what i was talking about above. Note : Don't ever say that you are Newbie.

    Hope the best for you.

  • »
    »
    2 months ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    In general, variables are used to store values, while pointers are used to store the memory address of a value. A pointer is a type of variable that holds the memory address of another variable. This allows the pointer to indirectly reference and manipulate the value of the other variable.

    For example, if we have an integer variable called "num" with a value of 5, we can use a pointer to store the memory address of "num" and indirectly access and modify its value. This can be useful in certain situations, such as when we want to pass the address of a variable to a function or when we want to dynamically allocate memory for a variable.

    Overall, the main difference between pointers and variables is that pointers store memory addresses, while variables store values.

»
2 months ago, # |
Rev. 2   Vote: I like it 0 Vote: I do not like it

HMMM.

Actually i've solved this problem like this:

Every time i face 2pointers problem i solve it after wasting time in debugging then i watch many codes for the same problems in editorial and LGM codes .

The idea behind this is you should see the standard codes for problems which solvable by 2pointers approach .

Best wishes .

»
2 months ago, # |
  Vote: I like it 0 Vote: I do not like it

The two pointer algorithm can be difficult because it involves maintaining and updating two pointers, which can be tricky to keep track of. It also requires careful consideration of the conditions and constraints of the problem in order to determine when to move the pointers and how to update them.

To improve your ability to write two pointer algorithms, it may be helpful to practice solving problems with this approach, and to carefully study the solutions to other problems that use the two pointer technique. It may also be helpful to discuss and learn from others who have experience with this algorithm.