• Skip to primary navigation
  • Skip to content
  • Skip to primary sidebar

Pro Programming

Professional way of Programming: Learn C, C++, Java, Python, Dot Net, Android the professional way

  • Home
  • C MCQs
  • C/C++ Programs
  • Java Programs
  • C#
  • Python
  • MySQL
  • Topics
    • Arrays
    • Strings
    • Link Lists
    • Trees
    • Shapes
  • Projects
  • Articles
  • Games
You are here: Home / Archives for What’s Difference?

What’s Difference?

Python | Convert case of elements in a list of strings

Leave a Comment


Given a list of strings, write a Python program to convert all string from lowercase/uppercase to uppercase/lowercase.

Input : ['GeEk', 'FOR', 'gEEKS']
Output: ['geeks', 'for', 'geeks']

Input : ['fun', 'Foo', 'BaR']
Output: ['FUN', 'FOO', 'BAR']

 
Method #1 : Convert Uppercase to Lowercase using map function

  

out = map(lambda x:x.lower(), ['GeEk', 'FOR', 'gEEKS'])

  

output = list(out)

  

print(output)

Output:


['geek', 'for', 'geeks']

 
Method #2: Convert Lowercase to Uppercase using List comprehension

  

input = ['fun', 'Foo', 'BaR']

  

lst = [x.upper() for x in input]

  

print(lst)

Output:


['FUN', 'FOO', 'BAR']




If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the “Improve Article” button below.

Article Tags :


thumb_up
Be the First to upvote.

Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.


Post navigation


Previous

first_page Python | Sum values for each key in nested dictionary










Source link

Filed Under: c programming Tagged With: •   Dynamic Programming, About Us, Advanced Data Structure, Advanced Topics, Algo ▼, Algorithm Paradigms ►, Algorithms, All Algorithms, All Data Structures, Amazon product price tracker using Python, Analysis of Algorithms, Aptitude, Array, Backtracking, Best Python libraries for Machine Learning, Binary Search (bisect) in Python, Binary Search Tree, Binary Tree, Bit Algorithms, Branch & Bound, C, Campus Ambassador Program, Careers, Check for balanced parentheses in Python, Company Prep, Company-wise, Competitive Programming, Compiler Design, Computer Graphics, Computer Networks, Computer Organization, Computer Organization & Architecture, Constructors in Python, Contact Us, Contests, contribute.geeksforgeeks.org, contributed articles, Core Subjects ►, Counting the frequencies in a list using dictionary in Python, Courses, CS Subjects, CS Subjects ▼, CS Subjectwise ►, CSS, Data Structures, DBMS, Dealing with Rows and Columns in Pandas DataFrame, Decorators in Python, Decorators with parameters in Python, Design Patterns, Digital Electronics, Divide and Conquer, Dividing a Large file into Separate Modules in C/C++, DS ▼, Engg. Mathematics, Experienced Interviews, Face Detection using Python and OpenCV with webcam, Functions in Python, Game Theory, GATE ▼, GATE 2019, GATE CS Corner, GATE Notes, GATE Official Papers, GBlog, Geek of the Month, Geek on the Top, Generating subarrays using recursion, Geometric Algorithms, Graph, Graph Algorithms, Greedy Algorithms, Hashing, Heap, How to assign values to variables in Python and other languages, HTML, HTML & XML, ide.geeksforgeeks.org, Indentation and Comment in Python, Inheritance in Python, Internship, Internship Interviews, Internships, Interview ▼, Interview Experiences, ISRO CS Exam, Java, Java and Python, JavaScript, Languages, Languages ►, Languages ▼, Last Minute Notes, Linear Regression Using Tensorflow, LinkedList, Machine Learning, Mathematical Algorithms, Matrix, Memoization using decorators in Python, Microprocessor, ML | Cancer cell classification using Scikit-learn, ML | Linear Regression, Multiple Choice Quizzes, Namespaces and Scope in Python, Operating Systems, Operator Overloading in Python, Output of Python Programs | (Dictionary), Pattern Searching, PHP, Placement Course, Polymorphism in Python, Practice, Practice Company Questions, Priority Queue in Python, Privacy Policy, Program Output, Project, Puzzles, Python, Python | Catching the ball game, Python | Convert a list into a tuple, Python | Convert a list of characters into a string, Python | Convert a list of multiple integers into a single integer, Python | Convert a list of Tuples into Dictionary, Python | Convert a nested list into a flat list, Python | Convert an array to an ordinary list with the same items, Python | Convert list of string to list of list, Python | Convert list of strings and characters to list of characters, Python | Convert number to list of integers, Python | Convert set into a list, Python | Count occurrences of a character in string, Python | Delete rows/columns from DataFrame using Pandas.drop(), Python | Frequency of each character in String, Python | Generate QR Code using pyqrcode module, Python | Image Classification using keras, Python | Implementation of Movie Recommender System, Python | Implementation of Polynomial Regression, Python | Maximum sum of elements of list in a list of lists, Python | NLP analysis of Restaurant reviews, Python | Output Formatting, Python | Output using print() function, Python | Pandas Split strings into two List/Columns using str.split(), Python | Program to convert String to a List, Python | Program to generate one-time password (OTP), Python | range() method, Python | Remove empty strings from list of strings, Python | Sum values for each key in nested dictionary, Python for Data Science, Python in Competitive Programming, Python List, Python list sort(), Python list-programs, Python program to add two numbers, Python program to check whether a number is Prime or not, Python program to convert a list to string, Python program to find day of the week for a given date, Python program to print all Prime numbers in an Interval, Python program to swap two elements in a list, Python Programs, Python regex to find sequences of one upper case letter followed by lower case letters, Python String, Queue, Quizzes ▼, Randomized Algorithms, School Programming, Searching Algorithms, Skip to content, Software Engineering, Some rights reserved, Sorting Algorithms, SQL, Stack, Statement, Strings, Structuring Python Programs, Students ▼, Subjective Questions, Suggest an Article, Taking input from console in Python, Taking input in Python, Taking multiple inputs from user in Python, Testimonials, Theory of Computation, Top Topics, Topic-wise, Topicwise ►, Tree based DS ►, UGC NET CS Paper II, UGC NET CS Paper III, UGC NET Papers, Video Tutorials, Videos, Web Technology, What’s Difference?, Write an Article, Write Interview Experience

Amazon Interview Experience SDE 1 (2.5 Years Experienced)

Leave a Comment


Got a message from HR on Linkedin that my profile has been shortlisted for SDE-2 profile

He sent me Invite for Interview in Amazon Gurgaon Office

 

Round 1 (Written Round)

 

Return Nth Node from the back of the linked list

https://www.geeksforgeeks.org/nth-node-from-the-end-of-a-linked-list/

 

Zigzag Traversal of Tree

https://www.geeksforgeeks.org/zigzag-tree-traversal/

 

Max length path between any two points in the given N*M  matrix such that all elements in that path are in increasing order

https://www.geeksforgeeks.org/find-the-longest-path-in-a-matrix-with-given-constraints/

 

Round 2 (DS/Algo Round)

 

Find the node in the linked list having a cycle where the loop starts.

https://www.geeksforgeeks.org/find-first-node-of-loop-in-a-linked-list/

 

I gave him well known slow and fast pointer solution instantly.

Then he told me to do the calculation and derive the formula why the above solution works.

I did the same.

 

Find two nodes where the sum is equal to a given sum in a BST.

https://www.geeksforgeeks.org/find-a-pair-with-given-sum-in-bst/

 

I didn’t know the stack solution so I thought in other direction.

I asked him can I modify the tree to which he replied YES.

I told him that we can convert the BST into DLL and then traverse the DLL taking two pointers one from each side and get the nodes with the given sum.

Since the time complexity was O(n) in this case so he got satisfied.

 

Round 3( Design Round)

Asked me about my projects in the current company.

Asked me to design High-level design for Latency Management System.

Asked me to design Low-level design for Library Management System.

Since I didn’t do well in design round, they considered me for SDE-1.

 

Round 4 (DS/Algo Round)

 

Edit Distance Problem of DP

https://www.geeksforgeeks.org/edit-distance-dp-5/

 

Water Trapping Problem

https://www.geeksforgeeks.org/trapping-rain-water/

 

Find maximum element in the sliding window of k elements in an array

https://www.geeksforgeeks.org/sliding-window-maximum-maximum-of-all-subarrays-of-size-k/

 

Then I was told by the HR to fly back to Chennai next week for further rounds. He arranged everything from flight tickets to accommodation.

 

Round 5(Managerial Round)

 

Discussed my current profile and projects in my current company.

Why I want to leave my current company.

Long Discussion about my projects.

One of my projects was to develop a notification service.

He found it of his interest and asked for a detailed explanation. He asked the difference between a service and program.

What is thrashing?

My 3 most challenging tasks I have worked on.

My 3 most boring tasks I have worked on.

My 3 strengths.

My 3 weaknesses.

Do you have ever faced a situation in which you have to stretch yourself?

As a child how did you see your future?

What is your favourite data structure and why?

What is O(n) and what’s its use?

Will you be able to relocate to Chennai?/ Do you have issues with relocation?

 

There was a lot of cross-questioning and he noted everything whatever I was saying.

 

Round 6(Bar raiser)

 

Discussed my current profile and projects in my current company.

Do you have issues with relocation? He told me a lot of candidates come here and then try to relocate back to other locations.

He took a deep dive into one of my projects and asked me questions like

What challenges you faced while doing this project and how you resolved them.

Why do you want to join Amazon?

 

In the end, he gave me a simple question to solve.

There is an array of integers, replace every number with its next greater element.

https://www.geeksforgeeks.org/replace-every-element-with-the-greatest-on-right-side/

 

Verdict: Got selected 🙂 


If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the “Improve Article” button below.

Article Tags :


thumb_up
Be the First to upvote.

Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.


Post navigation


Previous

first_page KLA Tencor Interview 2019







Source link

Filed Under: c programming Tagged With: •   Dynamic Programming, About Us, Accenture Interview Questions, Adobe Interview Experience (2 years experienced), Adobe Interview Experience | Set 37 (3.5 Years Experienced), Adobe Interview Experience | Set 38 (4.6 Years Experienced), Adobe Interview Experience | Set 39 (1.5 Years Experienced), Adobe Interview Experience for MTS-2, Advanced Data Structure, Advanced Topics, Algo ▼, Algorithm Paradigms ►, Algorithms, All Algorithms, All Data Structures, Amazon, Amazon India SDE III Interview Experience, Amazon Interview Experience | Set 245 (For 2.5 Years Experienced), Amazon Interview experience | Set 334 (For 4.5 Years Experienced), Amazon Interview Experience | Set 340 (3.5 years experienced for SDE 1), Amazon Interview Experience | Set 347 (1.8 Years Experienced for SDE1), Amazon Interview Experience | Set 357 (For 2.5 Years Experienced), Amazon interview experience for Experienced, Amazon interview experience for SDE II, Amazon Interview Experience SDE (On Campus 2019), Amazon Interview Experience SDE 1, Amazon Interview Experience SDE 2, Amazon Interview Experience SDE ll, Amazon Interview Experience SDE Off Campus, Amazon Interview Experience SDE2, Amazon SDE-2 Interview Experience, Amdocs Interview experience for Experienced candidate (2 - 5 yrs), Analysis of Algorithms, Aptitude, Array, Backtracking, Binary Search Tree, Binary Tree, Bit Algorithms, Branch & Bound, C, Campus Ambassador Program, Capgemini Interview Experience (2+ Experience), Careers, Cisco Interview | Experience : 2+ years, CodeNation Interview Experience | (On-Campus for SDE), Company Prep, Company-wise, Competitive Programming, Compiler Design, Computer Graphics, Computer Networks, Computer Organization, Computer Organization & Architecture, Contact Us, Contests, contribute.geeksforgeeks.org, Core Subjects ►, Courses, Coviam Interview Experience for SDE II (2.3 yr Experience), CS Subjects, CS Subjects ▼, CS Subjectwise ►, CSS, Data Structures, DBMS, Design Patterns, Digital Electronics, Divide and Conquer, Druva Interview Experience (1 Year Experienced), DS ▼, Dunzo Interview - Senior Software Engineer, Engg. Mathematics, Experienced, Experienced Interviews, Flipkart Interview Experience | SDE-1 (Experienced), Game Theory, GATE ▼, GATE 2019, GATE CS Corner, GATE Notes, GATE Official Papers, GBlog, GE India Interview Questions, Geek of the Month, Geek on the Top, Geometric Algorithms, Goldaman Sachs Interview Experience (1+ year experienced), Goldman Sachs Interview Experience (for Experienced), Goldman Sachs Interview for SDE1 position(One year experienced)., Graph, Graph Algorithms, Greedy Algorithms, Hashing, Heap, HSBC Holdings Interview Experience (On Campus), HTML, HTML & XML, ide.geeksforgeeks.org, Internship, Internship Interviews, Internships, Interview ▼, Interview Experiences, Interview Rejections - How to handle?, ISRO CS Exam, Java, JavaScript, JP Morgan Chase Interview Questions, JP Morgan Interview experience | SDET Role for Experienced, KLA Tencor Interview 2019, KLA Tencor Interview Experience | Set 3, Languages, Languages ►, Languages ▼, Last Minute Notes, Lenskart 2+ year Experienced Interview Bangalore, LinkedList, Machine Learning, MakeMyTrip Interview Experience 2019, Mathematical Algorithms, Matrix, Microprocessor, Microsoft Interview Experience, Microsoft Interview Experience (Full Time 2018 Washington DC - with 2.5 years of experience), Microsoft Interview Experience (SDE II), Microsoft Interview Experience | (SDE-2 for 3 Years Experienced), Microsoft Interview Experience | Set 112 (For 4.5 Years Experienced), Microsoft Interview Experience | Set 154 (For 1.5 Years Experienced), Microsoft Interview for SDE-2, Morgan Stanley Interview | (For 2 years experienced), Multiple Choice Quizzes, Nagarro Interview Questions October 2018, National Instruments (NI Tech) Software Engineer (For 1.5 years experienced), Nearbuy Interview Experience | Set 4 (2 Years Experienced), OLA Interview Experience (Off-Campus), Operating Systems, Oracle Interview Experience | Set 45 (For 3 Years Experienced), OYO Interview Experience | Set 11 (For 2 years experienced), OYO Rooms Interview (2 years experienced), Pattern Searching, Paytm Interview - Software Engineer, PayTM Interview Experience (1 Year Experienced), Paytm Interview Experience (For Experienced), PayTm Interview Experience | Set 23 (For 2 Years Experienced), PayU Interview Experience - Senior Software Engineer, PHP, Placement Course, Poshmark Interview Experience, Practice, Practice Company Questions, Privacy Policy, Program Output, Project, Puzzles, Python, Queue, Quizzes ▼, Randomized Algorithms, Samsung R & D Campus drive 2018, School Programming, Searching Algorithms, Siemens Healthineers Interview Experience | Cloud/Angular | ~2 years experienced, Skip to content, Snapdeal Interview Experience for React developer, Software Engineering, Some rights reserved, Sorting Algorithms, SQL, Stack, Standard Chartered Interview Questions, Strings, Students ▼, Subjective Questions, TCS Ninja Interview Experience (CSE) 2018 (In-Details), Testimonials, Theory of Computation, Top Topics, Topic-wise, Topicwise ►, Tree based DS ►, UGC NET CS Paper II, UGC NET CS Paper III, UGC NET Papers, Video Tutorials, Videos, Walmart Engineer 3 interview experience, Web Technology, What’s Difference?, Write an Article, Write Interview Experience, Write your Interview Experience, Zoho interview for 2 years Experienced Java, Zookr.in Interview Experience

Amazon Interview Experience SDE Off Campus

Leave a Comment


Written Round: (1 hour)

  1. Given a linked list and K, print the last K nodes in reverse order.
    example: 1->2->3->4->5->6, K = 3 output: 6 5 4
  2. Find out whether the given tree is BST or not.
  3. Rotate Given matrix by 90 clockwise.

Technical Round: (1 hour)

  1. Given an array, for every element in the array, you need to print the product of all except the ith element itself.
  2. Given N train with their arrival and departure timings, you need to find the minimum number of platforms are required to accommodate all. The condition is, no train has to wait to get the free platform.

Technical Round: (1 hour)

  1. Define your own data structure that should do two operations at its best complexity.
  • insert(num): insert num into the data structure.
  • find(sum): return a pair(a, b) such that a+b = sum, if no such pair exists return -1.

2. Give a graph find out whether it is a tree or not.

Managerial Round: (1 hour)


  1. Long discussions on my projects.
  2. Have you disagreed with your manager’s opinion?
  3. Technical Challenges faced so far in the current role?
  4. Any technical solution provided by you to your team? Why your solution was better? and what was the outcome?
  5. Why are you looking for opportunities?
  6. Why Amazon?

Bar Raised Round: (1 hour)

  1. Long discussions on my project and current role?
  2. Long discussion on the trie data structure, comparison with other data structures.
  3. Why are you leaving your current role?
  4. Why Amazon?
  5. Given an array of integers, find out the range of contiguous elements with Largest sum. (Kadane’s algorithm)


If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the “Improve Article” button below.

Article Tags :


thumb_up
Be the First to upvote.

Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.


Post navigation


Previous

first_page Amazon Interview Experience SDE ll










Source link

Filed Under: c programming Tagged With: •   Dynamic Programming, About Us, Adobe Interview Experience (For MTS-1), Adobe Interview Experience for MTS-2, Adobe interview questions - Computer Scientist, Advanced Data Structure, Advanced Topics, Algo ▼, Algorithm Paradigms ►, Algorithms, All Algorithms, All Data Structures, Amazon, Amazon internship interview experience (on campus), Amazon Interview Experience, Amazon Interview Experience (On campus 2018), Amazon Interview Experience (On-Campus), Amazon Interview Experience | SDE-1 offcampus, Amazon Interview Experience | Set 283 (On-Campus), Amazon Interview Experience | Set 285 (On-Campus for JD-SDE), Amazon Interview Experience | Set 286 (On-Campus), Amazon Interview Experience | Set 293 (On-Campus), Amazon Interview Experience | Set 295 (On Campus), Amazon Interview Experience | Set 297 (On-Campus for SDE), Amazon Interview Experience | Set 298 (On-Campus for SDE-1), Amazon Interview Experience | Set 302 (On-Campus), Amazon Interview Experience | Set 303 (On-Campus), Amazon Interview Experience | Set 306 (On-Campus), Amazon Interview Experience | Set 307 (Off-Campus), Amazon Interview Experience | Set 390 (On-Campus), Amazon interview experience | Set 397 (On-Campus), Amazon interview experience | Set 398 (On-Campus), Amazon interview experience for Experienced, Amazon interview experience for SDE II, Amazon Interview Experience SDE (On Campus 2019), Amazon Interview Experience SDE 1, Amazon Interview Experience SDE 2, Amazon Interview Experience SDE ll, Amazon Interview Experience SDE2, Amazon SDE-2 Interview Experience, Analysis of Algorithms, Aptitude, Arcesium Interview Experience ( FTE On-Campus), Arcesium Interview Experience (On Campus for FTE), Array, Backtracking, Bangalore, Binary Search Tree, Binary Tree, Bit Algorithms, Branch & Bound, C, Campus Ambassador Program, Careers, CodeNation Interview Experience | (On-Campus for SDE), Company Prep, Company-wise, Competitive Programming, Compiler Design, Computer Graphics, Computer Networks, Computer Organization, Computer Organization & Architecture, Contact Us, Contests, contribute.geeksforgeeks.org, Core Subjects ►, Courses, Coviam Software Developer Internship Experience, CS Subjects, CS Subjects ▼, CS Subjectwise ►, CSS, Data Structures, DBMS, DBMS | Join operation Vs nested query, Design Patterns, Digital Electronics, Divide and Conquer, DS ▼, Endurance Interview Experience (On-Campus), Engg. Mathematics, Experienced Interviews, Flipkart On Campus Interview, Game Theory, GATE ▼, GATE 2019, GATE CS Corner, GATE Notes, GATE Official Papers, GBlog, Geek of the Month, Geek on the Top, Geometric Algorithms, Goldaman Sachs Interview Experience (1+ year experienced), Goldman Sachs Interview (for Experienced), Goldman Sachs Interview Experience (for Experienced), Goldman Sachs Interview Experience 2018, Goldman Sachs Interview for SDE1 position(One year experienced)., Goldman Sachs on campus Internship Experience for summer 2019, Graph, Graph Algorithms, Greedy Algorithms, Hashing, Heap, How I cracked Cognizant and Accenture placement drive, How Should a Fresher Prepare for a Job Interview?, HTML, HTML & XML, ide.geeksforgeeks.org, Internship, Internship Interviews, Internships, Interview ▼, Interview Experiences, ISRO CS Exam, Java, JavaScript, Languages, Languages ►, Languages ▼, Last Minute Notes, LinkedList, Machine Learning, MakeMyTrip Interview Experience 2019, Mathematical Algorithms, Matrix, Microprocessor, Microsoft IDC Internship On-Campus Interview Experience 2018, Microsoft IDC Interview Experience, Microsoft IDC Interview Experience (On Campus Internship), Microsoft Interview Experience (Internship 2018), Microsoft Interview Experience (On-Campus Internships 2018), Microsoft Interview Experience | SDE - 2018, Microsoft Interview experience | Set 178 (On-Campus Internship for IDC), Microsoft Interview Experience 2018 @ IIT, Microsoft Interview Interview Experience for Full Time, Multiple Choice Quizzes, Off-Campus, Off-Campus Placement Preparation, Operating Systems, OYO Rooms Interview Experience (On-Campus), Pattern Searching, Paytm Interview Experience (For Experienced), PHP, Placement Course, Practice, Practice Company Questions, Privacy Policy, Program Output, Project, Puzzles, Python, Queue, Quizzes ▼, Randomized Algorithms, Samsung Bangalore Interview Experience for Research Profile, Samsung Interview Experience | (On-Campus for R & D Noida), Samsung R & D Banglore Intern Interview Experience, Samsung R & D Campus drive 2018, Samsung R & D internship Interview, Samsung R & D Noida Question September 2018, Samsung RnD Bangalore Interview 2018, Samsung Semiconductor Institute of Research(SSIR Software) Intern/FTE | Set-2, School Programming, Searching Algorithms, Skip to content, Software Engineer Interview at Google, Software Engineering, Some rights reserved, Sorting Algorithms, SQL, SRI Delhi Interview Experience (On Campus for Software Engineer), Stack, Strings, Students ▼, Subjective Questions, Testimonials, Theory of Computation, Top Topics, Topic-wise, Topicwise ►, Tree based DS ►, Uber Interview Experience (On Campus for Internship 2018-19), UGC NET CS Paper II, UGC NET CS Paper III, UGC NET Papers, Video Tutorials, Videos, Web Technology, What’s Difference?, Wipro Elite Interview Experience (On Campus), Write an Article, Write Interview Experience, Write your Interview Experience

Method resolution order in Python Inheritance

Leave a Comment


Method Resolution Order :
Method Resolution Order(MRO) it denotes the way a programming language resolves a method or attribute. Python supports classes inheriting from other classes. The class being inherited is called the Parent or Superclass, while the class that inherits is called the Child or Subclass. In python, method resolution order defines the order in which the base classes are searched when executing a method. First, the method or attribute is searched within a class and then it follows the order we specified while inheriting. This order is also called Linearization of a class and set of rules are called MRO(Method Resolution Order). While inheriting from another class, the interpreter needs a way to resolve the methods that are being called via an instance. Thus we need the method resolution order. For Example

  

class A:

    def rk(self):

        print(" In class A")

class B(A):

    def rk(self):

        print(" In class B")

  

r = B()

r.rk()

Output:

C++
1
2
3
4
5
6
 
 

In class B
 
 

In the above example the methods that are invoked is from class B but not from class A, and this is due to Method Resolution Order(MRO).
The order that follows in the above code is- class B - > class A
In multiple inheritances, the methods are executed based on the order specified while inheriting the classes. For the languages that support single inheritance, method resolution order is not interesting, but the languages that support multiple inheritance method resolution order plays a very crucial role. Let’s look over another example to deeply understand the method resolution order:

  

class A:

    def rk(self):

        print(" In class A")

class B(A):

    def rk(self):

        print(" In class B")

class C(A):

    def rk(self):

        print("In class C")

  

class D(B, C):

    pass

     

r = D()

r.rk()

Output:

C++
1
2
3
4
5
6
 
 

In class B
 
 

In the above example we use multiple inheritances and it is also called Diamond inheritance or Deadly Diamond of Death and it looks as follows:

Python follows a depth-first lookup order and hence ends up calling the method from class A. By following the method resolution order, the lookup order as follows.
Class D -> Class B -> Class C -> Class A
Python follows depth-first order to resolve the methods and attributes. So in the above example, it executes the method in class B.
 
Old and New Style Order :
In the older version of Python(2.1) we are bound to use old-style classes but in Python(3.x & 2.2) we are bound to use only new classes. New style classes are the ones whose first parent inherits from Python root ‘object’ class.


class OldStyleClass: 

    pass

  

class NewStyleClass(object): 

    pass

Method resolution order(MRO) in both the declaration style is different. Old style classes use DLR or depth-first left to right algorithm whereas new style classes use C3 Linearization algorithm for method resolution while doing multiple inheritances.
 
DLR Algorithm
During implementing multiple inheritances, Python builds a list of classes to search as it needs to resolve which method has to be called when one is invoked by an instance. As the name suggests, the method resolution order will search the depth-first, then go left to right. For Example

class A: 

    pass

  

  

class B: 

    pass

  

  

class C(A, B): 

    pass

  

  

class D(B, A): 

    pass

  

  

class E(C,D): 

    pass

In the above Example algorithm first looks into the instance class for the invoked method. If not present, then it looks into the first parent, if that too is not present then-parent of the parent is looked into. This continues till the end of the depth of class and finally, till the end of inherited classes. So, the resolution order in our last example will be D, B, A, C, A. But, A cannot be twice present thus, the order will be D, B, A, C. But this algorithm varying in different ways and showing different behaviours at different times .So Samuele Pedroni first discovered an inconsistency and introduce C3 Linearization algorithm.
 
C3 Linearization Algorithm :
C3 Linearization algorithm is an algorithm that uses new-style classes. It is used to remove an inconsistency created by DLR Algorithm. It has certain limitation they are:

  • Children precede their parents
  • If a class inherits from multiple classes, they are kept in the order specified in the tuple of the base class.

C3 Linearization Algorithm works on three rules:

  • Inheritance graph determines the structure of method resolution order.
  • User have to visit the super class only after the method of the local classes are visited.
  • Monotonicity

 
Methods for Method Resolution Order(MRO) of a class:
To get the method resolution order of a class we can use either __mro__ attribute or mro() method. By using these methods we can display the order in which methods are resolved. For Example

  

class A:

    def rk(self):

        print(" In class A")

class B:

    def rk(self):

        print(" In class B")

  

class C(A, B):

    def __init__(self):

        print("Constructor C")

  

r = C()

  

print(C.__mro__)

print(C.mro())

Output:

C++
1
2
3
4
5
6
7
8
 
 

Constructor C
(<class '__main__.C'>, <class '__main__.A'>, <class '__main__.B'>, <class 'object'>)
[<class '__main__.C'>, <class '__main__.A'>, <class '__main__.B'>, <class 'object'>]
 
 





If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the “Improve Article” button below.

Article Tags :


thumb_up
Be the First to upvote.

Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.


Post navigation


Previous

first_page Print first n distinct permutations of string using itertools in Python







Source link

Filed Under: c programming Tagged With: •   Dynamic Programming, 10 Interesting Python Cool Tricks, About Us, Advanced Data Structure, Advanced Topics, Algo ▼, Algorithm Paradigms ►, Algorithms, All Algorithms, All Data Structures, Analysis of Algorithms, Analyzing Mobile Data Speeds from TRAI with Pandas, Aptitude, Array, Backtracking, Binary Search Tree, Binary Tree, Bit Algorithms, Branch & Bound, C, Campus Ambassador Program, Careers, class method vs static method in Python, Company Prep, Company-wise, Competitive Programming, Compiler Design, Computer Graphics, Computer Network | Address Resolution in DNS, Computer Networks, Computer Organization, Computer Organization & Architecture, Contact Us, Contests, contribute.geeksforgeeks.org, contributed articles, Conversion Functions in Pandas DataFrame, Core Subjects ►, Counting the frequencies in a list using dictionary in Python, Courses, Creating a dataframe using Excel files, Cristian's Algorithm, CS Subjects, CS Subjects ▼, CS Subjectwise ►, CSS, Data Structures, DBMS, Dealing with Rows and Columns in Pandas DataFrame, Decorators in Python, Design Patterns, Destructors in Python, Different ways to iterate over rows in Pandas Dataframe, Digital Electronics, Divide and Conquer, DS ▼, Engg. Mathematics, examples of object, Experienced Interviews, Face Detection using Python and OpenCV with webcam, Game Theory, GATE ▼, GATE 2019, GATE CS Corner, GATE Notes, GATE Official Papers, GBlog, Geek of the Month, Geek on the Top, Generating random number list in Python, Generating subarrays using recursion, Geometric Algorithms, Graph, Graph Algorithms, Greedy Algorithms, Hashing, Heap, heapq in Python to print all elements in sorted order from row and column wise sorted matrix, How to assign values to variables in Python and other languages, HTML, HTML & XML, ide.geeksforgeeks.org, Indentation and Comment in Python, Inheritance in Python, Inheritance in Python | Set 2, Internship, Internship Interviews, Internships, Interview ▼, Interview Experiences, ISRO CS Exam, issubclass and super), Java, JavaScript, Languages, Languages ►, Languages ▼, Last Minute Notes, Linear Regression Using Tensorflow, LinkedList, Logic Gates in Python, Machine Learning, Mathematical Algorithms, Matrix, Microprocessor, ML | Cancer cell classification using Scikit-learn, Multiple Choice Quizzes, Namespaces and Scope in Python, OOP in Python | Set 3 (Inheritance, Operating Systems, Operator Overloading in Python, Output of Python Programs | (Dictionary), Overuse of lambda expressions in Python, Pattern Searching, PHP, Placement Course, Polymorphism in Python, Practice, Practice Company Questions, Print first n distinct permutations of string using itertools in Python, Priority Queue in Python, Privacy Policy, Program Output, Project, Puzzles, Python, Python | Automating Happy Birthday post on Facebook using Selenium, Python | Catching the ball game, Python | Check order of character in string using OrderedDict( ), Python | Count occurrences of a character in string, Python | Delete rows/columns from DataFrame using Pandas.drop(), Python | Get the real time currency exchange rate, Python | Implementation of Movie Recommender System, Python | Inserting item in sorted list maintaining order, Python | NLP analysis of Restaurant reviews, Python | Output Formatting, Python | Output using print() function, Python | Pandas TimedeltaIndex.resolution, Python | Plotting Doughnut charts in excel sheet using XlsxWriter module, Python | Program to generate one-time password (OTP), Python | range() method, Python | Real time currency convertor using Tkinter, Python | Real time weather detection using Tkinter, Python | Removing dictionary from list of dictionaries, Python | Simple FLAMES game using Tkinter, Python | Sort Python Dictionaries by Key or Value, Python | Sort Tuples in Increasing Order by any key, Python | Sort words of sentence in ascending order, Python | Tokenize text using TextBlob, Python code to print common characters of two Strings in alphabetical order, Python in Competitive Programming, Python List Comprehension | Sort even-placed elements in increasing and odd-placed in decreasing order, Python list sort(), Python program to add two numbers, Python program to check whether a number is Prime or not, Python program to count words in a sentence, Python-Functions, python-inheritance, Queue, Quizzes ▼, Randomized Algorithms, School Programming, Scope Resolution in Python | LEGB Rule, Searching Algorithms, Skip to content, Software Engineering, Some rights reserved, Sort the words in lexicographical order in Python, Sorting Algorithms, SQL, Stack, Statement, Strings, Structuring Python Programs, Students ▼, Subjective Questions, Taking input from console in Python, Taking input in Python, Taking multiple inputs from user in Python, Technical Scripter, Testimonials, Theory of Computation, Top Topics, Topic-wise, Topicwise ►, Tree based DS ►, UGC NET CS Paper II, UGC NET CS Paper III, UGC NET Papers, Video Tutorials, Videos, Web Technology, What is the Python Global Interpreter Lock (GIL), What’s Difference?, Working With JSON Data in Python, Working with Missing Data in Pandas, Write an Article, Write Interview Experience

host command in Linux with examples

Leave a Comment


host command in Linux system is used for DNS (Domain Name System) lookup operations. In simple words, this command is used to find the IP address of a particular domain name or if you want to find out the domain name of a particular IP address the host command becomes handy. You can also find more specific details of a domain by specifying the corresponding option along with the domain name.

Syntax:

C++
1
2
3
4
5
6
7
 
 

host [-aCdlriTWV] [-c class] [-N ndots] [-t type] [-W time]
     [-R number] [-m flag] hostname [server]
 
 

host command without any option: It will print the general syntax of the command along with the various options that can be used with the host command as well as gives a brief description about each option.

Example:

Different options with the host command:

  • host domain_name: This will print the IP address details of the specified domain.

    Example:

    C++
    1
    2
    3
    4
    5
     
     
    host geeksforgeeks.org
     
     

  • host IP_Address: This will display the domain details of the specified IP Address.

    Example:

    C++
    1
    2
    3
    4
    5
     
     
    host 52.25.109.230
     
     

  • -a or -v: It used to specify the query type or enables the verbose output.

    Example:

    C++
    1
    2
    3
    4
    5
     
     
    host -a geeksforgeeks.org
     
     

  • -t : It is used to specify the type of query.

    Example 1:

    C++
    1
    2
    3
    4
    5
     
     
    host -t ns geeksforgeeks.org  
     
     

    Example 2: To print SOA record

    C++
    1
    2
    3
    4
    5
     
     
    host -t SOA geeksforgeeks.org  
     
     

    Example 3: To print txt record

    C++
    1
    2
    3
    4
    5
     
     
    host -t txt geeksforgeeks.org  
     
     

  • -C : In order to compare the SOA records on authoritative nameservers.

    Example:

    C++
    1
    2
    3
    4
    5
     
     
    host -C geeksforgeeks.org
     
     

  • -R : In order to specify the number of retries you can do in case one try fails. If anyone try succeeds then the command stops.

    Example:

    C++
    1
    2
    3
    4
    5
     
     
    host -R 3 geeksforgeeks.org
     
     

  • -l :In order to list all hosts in a domain.For this command to work you need to be either an admin or a node server.

    Example:

    C++
    1
    2
    3
    4
    5
     
     
    host -l geeksforgeeks.org
     
     




If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the “Improve Article” button below.

Article Tags :


thumb_up
Be the First to upvote.

Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.


Post navigation


Previous

first_page Interesting Facts about Ubuntu










Source link

Filed Under: c programming Tagged With: •   Dynamic Programming, About Us, Advanced Data Structure, Advanced Topics, Algo ▼, Algorithm Paradigms ►, Algorithms, alias command in Linux with Examples, All Algorithms, All Data Structures, Analysis of Algorithms, Aptitude, Array, Backtracking, Bash shell script to swap two numbers, Basic Operators in Shell Scripting, bg command in Linux with Examples, Binary Search Tree, Binary Tree, Bit Algorithms, Branch & Bound, C, cal command in Linux with Examples, Campus Ambassador Program, Careers, cd command in Linux with Examples, chage command in Linux with examples, chpasswd command in Linux with examples, clear command in Linux with examples, Communication between two process using signals in C, Company Prep, Company-wise, Competitive Programming, Compiler Design, Computer Graphics, Computer Networks, Computer Organization, Computer Organization & Architecture, Conditional Statements | Shell Script, Contact Us, Contests, continue command in Linux with examples, contribute.geeksforgeeks.org, contributed articles, Core Subjects ►, Courses, cp command in Linux with examples, Creating a C++ template in vim in Linux, CS Subjects, CS Subjects ▼, CS Subjectwise ►, CSS, cut command in Linux with examples, Data Structures, DBMS, Design Patterns, df Command in Linux with examples, Different Shells in Linux, Digital Electronics, dir command in Linux with examples, dirname command in Linux with examples, Divide and Conquer, DS ▼, echo command in Linux with Examples, emacs command in Linux with examples, Engg. Mathematics, env command in Linux with Examples, Environment Variables in Linux/Unix, eval command in Linux with Examples, exit command in Linux with Examples, Experienced Interviews, expr command in Linux with examples, factor command in Linux with examples, fc Command in Linux with Examples, fg command in Linux with examples, fgrep command in Linux with examples, function command in Linux with examples, Game Theory, GATE ▼, GATE 2019, GATE CS Corner, GATE Notes, GATE Official Papers, GBlog, Geek of the Month, Geek on the Top, Geometric Algorithms, Graph, Graph Algorithms, Greedy Algorithms, groups command in Linux with examples, Hashing, Heap, hexdump command in Linux with examples, history command in Linux with Examples, hostid command in Linux with examples, How to setup cron jobs in Ubuntu, How to setup firewall in Linux?, HTML, HTML & XML, ide.geeksforgeeks.org, Interesting Facts about Ubuntu, Internship, Internship Interviews, Internships, Interview ▼, Interview Experiences, ISRO CS Exam, Java, JavaScript, kill command in Linux with Examples, Languages, Languages ►, Languages ▼, Last Minute Notes, less command in Linux with Examples, LinkedList, Linux | Nmon, Linux Networking Tools, linux-command, Linux-Unix, Looping Statements | Shell Script, lsmod command in Linux with Examples, Machine Learning, man command in Linux with Examples, Mathematical Algorithms, Matrix, Microprocessor, mkdir command in Linux with Examples, Multiple Choice Quizzes, nslookup command in Linux with Examples, Operating Systems, Pattern Searching, Perform DDoS attack using Torshammer, PHP, Picked, Placement Course, Practice, Practice Company Questions, Privacy Policy, Process states and Transitions in a UNIX Process, Program Output, Programs for printing different patterns in Bash, Project, ps command in Linux with Examples, Puzzles, pwd command in Linux with Examples, Python, Queue, Quizzes ▼, Randomized Algorithms, rcp Command in Linux with examples, rm command in Linux with examples, Run commands as root with sudo, Running previous command with sudo, School Programming, sdiff command in Linux with Examples, Searching Algorithms, shutdown command in Linux with Examples, Skip to content, Software Engineering, Some rights reserved, Sorting Algorithms, SQL, Stack, String Operators | Shell Script, Strings, Students ▼, Subjective Questions, sudo command in Linux with Examples, tar command in Linux with examples, TCP Server-Client implementation in C, tee command in Linux with examples, Testimonials, Theory of Computation, Top Topics, Topic-wise, Topicwise ►, touch command in Linux with Examples, Tree based DS ►, UGC NET CS Paper II, UGC NET CS Paper III, UGC NET Papers, uname command in Linux with Examples, Video Tutorials, Videos, Web Technology, What to do when load on a Linux based web server goes high?, What’s Difference?, Write an Article, Write Interview Experience

Minimum removals in a number to be divisible by 10 power raised to K

Leave a Comment


Given two positive integers N and K. Find the minimum number of digits that can be removed from the number N such that after removals the number is divisible by 10K or print -1 if it is impossible.

Examples:

C++
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
 
 

<strong>Input :</strong> N = 10904025, K = 2&#13;
<strong>Output :</strong> 3&#13;
<strong>Explanation :</strong> We can remove the digits 4, 2 and 5 such that the number &#13;
becomes 10900 which is divisible by 10<sup>2</sup>.&#13;
&#13;
<strong>Input :</strong> N = 1000, K = 5&#13;
<strong>Output :</strong> 3&#13;
<strong>Explanation :</strong> We can remove the digits 1 and any two zeroes such that the&#13;
number becomes 0 which is divisible by 10<sup>5</sup><strong>Input :</strong> N = 23985, K = 2&#13;
<strong>Output :</strong> -1&#13;
 
 

Approach : The idea is to start traversing the number from the last digit while keeping a counter. If the current digit is not zero, increment the counter variable, otherwise decrement variable K. When K becomes zero, return counter as answer. After traversing the whole number, check if the current value of K is zero or not. If it is zero, return counter as answer, otherwise return answer as number of digits in N – 1, since we need to reduce the whole number to a single zero which is divisible by any number. Also, if the given number does not contain any zero, return -1 as answer.

Below is the implementation of above approach.

#include <bits/stdc++.h>

using namespace std;

  

int countDigitsToBeRemoved(int N, int K)

{

    

    

    string s = to_string(N);

  

    

    

    int res = 0;

  

    

    

    int f_zero = 0;

    for (int i = s.size() - 1; i >= 0; i--) {

        if (K == 0)

            return res;

        if (s[i] == '0') {

  

            

            f_zero = 1;

            K--;

        }

        else

            res++;

    }

  

    

    

    

    if (!K)

        return res;

    else if (f_zero)

        return s.size() - 1;

    return -1;

}

  

int main()

{

    int N = 10904025, K = 2;

    cout << countDigitsToBeRemoved(N, K) << endl;

  

    N = 1000, K = 5;

    cout << countDigitsToBeRemoved(N, K) << endl;

  

    N = 23985, K = 2;

    cout << countDigitsToBeRemoved(N, K) << endl;

    return 0;

}

Time Complexity :Number of digits in the given number.




If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the “Improve Article” button below.

Article Tags :


thumb_up
Be the First to upvote.

Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.


Post navigation


Previous

first_page Subset Sum Queries in a Range using Bitset







Source link

Filed Under: c programming Tagged With: •   Dynamic Programming, About Us, Advanced Data Structure, Advanced Topics, Algo ▼, Algorithm Paradigms ►, Algorithms, All Algorithms, All Data Structures, Analysis of Algorithms, Aptitude, Array, Backtracking, Berkeley's Algorithm, Binary Search Tree, Binary Tree, Bit Algorithms, Branch & Bound, C, Campus Ambassador Program, Careers, Check if a number can be expressed as x^y (x raised to power y), Check if given number is a power of d where d is a power of 2, Check if item can be measured using a scale and some weights, Company Prep, Company-wise, Competitive Programming, Compiler Design, Computer Graphics, Computer Networks, Computer Organization, Computer Organization & Architecture, Construct a binary string following the given constraints, Contact Us, Contests, contribute.geeksforgeeks.org, contributed articles, Core Subjects ►, Count all possible position that can be reached by Modified Knight, Count unique subsequences of length K, Count valid pairs in the array satisfying given conditions, Courses, Cristian's Algorithm, CS Subjects, CS Subjects ▼, CS Subjectwise ►, CSS, Cyclomatic Complexity, Data Structures, DBMS, Design Patterns, Difference between Algorithm, Difference between Deterministic and Non-deterministic Algorithms, Digital Electronics, Dijkstra's shortest path with minimum edges, Divide and Conquer, divisibility, DS ▼, Egg Dropping Puzzle with 2 Eggs and K Floors, Eggs dropping puzzle (Binomial Coefficient and Binary Search Solution), Engg. Mathematics, Experienced Interviews, Expressing a fraction as a natural number under modulo 'm', Find alphabet in a Matrix which has maximum number of stars around it, Find i’th index character in a binary string obtained after n iterations | Set 2, Find maximum in a stack in O(1) time and O(1) extra space, Find multiple of x closest to or a ^ b (a raised to power b), Find the minimum positive integer such that it is divisible by A and sum of its digits is equal to B, Find the number of distinct islands in a 2D matrix, Find unit digit of x raised to power y, Find value of y mod (2 raised to power x), Game Theory, GATE ▼, GATE 2019, GATE CS Corner, GATE Notes, GATE Official Papers, GBlog, GCD of a number raised to some power and another number, Geek of the Month, Geek on the Top, Geometric Algorithms, Graph, Graph Algorithms, Greedy Algorithms, Hashing, Heap, How can one become good at Data structures and Algorithms easily?, HTML, HTML & XML, ide.geeksforgeeks.org, Internship, Internship Interviews, Internships, Interview ▼, Interview Experiences, ISRO CS Exam, Java, JavaScript, K-th digit in 'a' raised to power 'b', Languages, Languages ►, Languages ▼, Larger of a^b or b^a (a raised to power b or b raised to power a), Largest Divisor of a Number not divisible by a perfect square, Largest factor of a given number which is a perfect square, Largest number in an array that is not a perfect cube, Largest perfect square number in an Array, Last Minute Notes, Length of largest sub-array having primes strictly greater than non-primes, LinkedList, Lower and Upper Bound Theory, Machine Learning, Mathematical, Mathematical Algorithms, maths-power, Matrix, Maximize the total profit of all the persons, Maximum and Minimum element of a linked list which is divisible by a given number k, Maximum possible time that can be formed from four digits, Microprocessor, Minimum and Maximum element of an array which is divisible by a given number k, Minimum cost to reach the top of the floor by climbing stairs, Minimum number of changes required to make the given array an AP, Minimum number of items to be delivered, Minimum number of moves to make all elements equal, Minimum number of power terms with sum equal to n, Minimum odd cost path in a matrix, Minimum removals from array to make GCD greater, Minimum splits in a binary string such that every substring is a power of 4 or 6., Minimum steps to reach target by a Knight | Set 2, Multiple Choice Quizzes, Number of balanced bracket expressions that can be formed from a string, Number of digits in 2 raised to power n, Number of special pairs possible from the given two numbers, number-digits, Operating Systems, Optimal sequence for AVL tree insertion (without any rotations), Pattern Searching, PHP, Placement Course, Practice, Practice Company Questions, Prim's Algorithm (Simple Implementation for Adjacency Matrix Representation), Print last k digits of a^b (a raised to power b), Print the nodes of binary tree as they become the leaf node, Privacy Policy, Program for SSTF disk scheduling algorithm, Program Output, Program to print the Zigzag pattern, Project, Pseudocode and Program, Puzzles, Python, Queries of nCr%p in O(1) time complexity, Queries to check whether a given digit is present in the given Range, Queue, Quick Sort vs Merge Sort, Quizzes ▼, Randomized Algorithms, Range and Update Sum Queries with Factorial, Range Sum Queries and Update with Square Root, Reduce the array to a single element with the given operation, Samsung Semiconductor Institute of Research(SSIR Software) intern/FTE | Set-3, School Programming, Searching Algorithms, Shannon-Fano Algorithm for Data Compression, Skip to content, Smallest Greater (than S) String of length K whose letters are subset of S, Smallest Pair Sum in an array, Software Engineering, Some rights reserved, Sort only non-prime numbers of an array in increasing order, Sorting Algorithms, SQL, Stack, Strings, Students ▼, Subjective Questions, Subset Sum Queries in a Range using Bitset, Sum of similarities of string with all of its suffixes, Sum of the minimum elements in all connected components of an undirected graph, Technical Scripter 2018, Testimonials, Theory of Computation, Top Topics, Topic-wise, Topicwise ►, Tree based DS ►, UGC NET CS Paper II, UGC NET CS Paper III, UGC NET Papers, Video Tutorials, Videos, Web Technology, What’s Difference?, Write an Article, Write Interview Experience

  • Page 1
  • Page 2
  • Page 3
  • Next Page »

Primary Sidebar

Recent Posts

  • Solid State Chemistry Questions and Answers – Intensities
  • Python | Convert case of elements in a list of strings
  • Java String Array to String Example
  • 14. Two-way data binding with v-model
  • Solid State Chemistry Questions and Answers – Modern X-Ray Powder Techniques and their Applications
  • Privacy Policy
  • About
  • Contact US

© 2019 ProProgramming
 Privacy Policy About Contact Us