Skip to main content
Used more apt terms
Source Link

Test case includes total 100K operations of pushenqueue, popdequeue and show_topshow_front. Each item is of 9 digits.

Test case includes total 100K operations of push, pop and show_top. Each item is of 9 digits.

Test case includes total 100K operations of enqueue, dequeue and show_front. Each item is of 9 digits.

deleted 86 characters in body; edited title
Source Link
Jamal
  • 34.9k
  • 13
  • 133
  • 237

Slow python list List operation while implementing stack

This is a very basic problem of implementing a queue operation using two stacks.

TillUntil now there are no issues with the logic but the testing tool report it takes more time than usual.

The test tool expects it to be completed by 10seconds10 seconds.

TriedI tried with both pythonPython way and traditional algorithmic way but both did not help.

Could I could not find much content with pythonPython list optimization that I can map here.

  1. Qora link.

    Quora link
  2. StackOverflow link.

    Stack Overflow link

Listed two of the implementations for reference.:

Try - 1:

Try 1:


Try - 2:

Try 2:


 

NotI'm not able to understand if append, insert or pop is taking more time. (Would pre-allocated array of specified size help in pythonPython?)

Note-: The testing tool is from a web based platform for developers to practice coding. I I am making this question for suggestions about optimization that may help here.

Slow python list operation while implementing stack

This is a very basic problem of implementing queue operation using two stacks.

Till now there are no issues with the logic but the testing tool report it takes more time than usual.

The test tool expects it to be completed by 10seconds.

Tried with both python way and traditional algorithmic way but both did not help.

Could not find much content with python list optimization that I can map here.

  1. Qora link.

  2. StackOverflow link.

Listed two of the implementations for reference.

Try - 1:


Try - 2:


 

Not able to understand if append, insert or pop is taking more time. (Would pre-allocated array of specified size help in python)

Note- The testing tool is from a web based platform for developers to practice coding. I am making this question for suggestions about optimization that may help here.

List operation while implementing stack

This is a very basic problem of implementing a queue operation using two stacks.

Until now there are no issues with the logic but the testing tool report it takes more time than usual.

The test tool expects it to be completed by 10 seconds.

I tried with both Python way and traditional algorithmic way but both did not help. I could not find much content with Python list optimization that I can map here.

  1. Quora link
  2. Stack Overflow link

Listed two of the implementations for reference:

Try 1:

Try 2:

I'm not able to understand if append, insert or pop is taking more time. (Would pre-allocated array of specified size help in Python?)

Note: The testing tool is from a web based platform for developers to practice coding. I am making this question for suggestions about optimization that may help here.

deleted 9 characters in body
Source Link
Billal Begueradj
  • 3.4k
  • 10
  • 25
  • 34

This is a very basic problem of implementing queue operation using two stacks. Till

Till now there are no issues with the logic but the testing tool report it takes more time than usual.

Test case includes total 100K operations of push, pop and show_top. Each item is of 9 digits. The

The test tool expects it to be completed by 10seconds.

Could not find much content with python list optimization that I can map here. (1. https://www.quora.com/What-are-some-common-mistakes-that-could-slow-down-ones-Python-scripts

  1. https://stackoverflow.com/questions/1110332/performance-of-list-insert?utm_medium=organic&utm_source=google_rich_qa&utm_campaign=google_rich_qa)
  1. Qora link.

  2. StackOverflow link.

This is a very basic problem of implementing queue operation using two stacks. Till now there are no issues with the logic but the testing tool report it takes more time than usual.

Test case includes total 100K operations of push, pop and show_top. Each item is of 9 digits. The test tool expects it to be completed by 10seconds.

Could not find much content with python list optimization that I can map here. (1. https://www.quora.com/What-are-some-common-mistakes-that-could-slow-down-ones-Python-scripts

  1. https://stackoverflow.com/questions/1110332/performance-of-list-insert?utm_medium=organic&utm_source=google_rich_qa&utm_campaign=google_rich_qa)

This is a very basic problem of implementing queue operation using two stacks.

Till now there are no issues with the logic but the testing tool report it takes more time than usual.

Test case includes total 100K operations of push, pop and show_top. Each item is of 9 digits.

The test tool expects it to be completed by 10seconds.

Could not find much content with python list optimization that I can map here.

  1. Qora link.

  2. StackOverflow link.

Source Link
Loading