Posts

Anti-palindrome strings

You are given a string  S  containing only lowercase alphabets. You can swap two adjacent characters any number of times (including 0). A string is called anti-palindrome if it is not a palindrome. If it is possible to make a string anti-palindrome, then find the lexicographically smallest anti-palindrome.   Otherwise, print -1 − 1 Input format The first line contains a single integer  T  denoting the number of test cases. The description of  T  test cases follows. Each line contains a string  S   of lower case alphabets only. Output format For each test case, print the answer in a new line. Constraints 1 ≤ T ≤ 100 2 ≤ | S | ≤ 2 × 10 5 S  contains only lowercase alphabets. SAMPLE INPUT 4 bpc pp deep zyx SAMPLE OUTPUT bcp -1 deep xyz Explanation In the first test case, you can create "bcp" which is not a palindrome and it is a lexicographically-small...

Supernatural

You are given a number   n . A supernatural number is a number whose product of digits is equal to   n , and in this number there is no digit 1. Count the number of supernatural numbers for a given   n . Input Contains a single integer   n ,   1 <= n <= 100 . Output Print the number of supernatural numbers. SAMPLE INPUT 4 SAMPLE OUTPUT 2 Explanation There are only two natural numbers, the product of the digits of which is 4 - 4, 22.

CentOS / RHEL 7 : How to Reset root password

Image
Hey, everyone๐Ÿ˜€, I am Svastikkka when we are a beginner in Linux or we just started to use Linux operating system we always thought what if we forget the password of our Linux account it may be a root account or any other user-defined account so in here I am going to show that " how to reset the root password of Linux operating system account ". Also, it is important for the system administrator to know how to reset the root password. We consider RedHat operating system (RHEL7) to demonstrate how to reset the root password. Reset Root Password Step 1 Restart your system  Step 2 Press e on your keyboard when you see this screen: Step 3 If you've done this correctly, you should see a screen similar to this one: Step 4 Scroll down and find  "linux16" word and use your arrow keys to move to the "linux16" line: Step 5 In the last "linux16" line append  rd.break enforcing=0 Step 6 Press Ctrl-x to start...

Reverse Stack

Reverse a given Stack with the help of another empty stack. Two stacks will be given. Out of which first contains some integers and second one is empty. You need to reverse the first one using second stack. Change in the given first stack itself. Note : You don't need to print or return the stack, just reverse the given stack and it will be printed internally. Input format : Line 1 : Size of Stack Line 2 : Stack elements (separated by space) Sample Input 1 : 4 1 2 3 4 (4 is at top) Sample Output 1 : 1 2 3 4 (1 is at top)

Balanced Paranthesis

Given a string expression, check if brackets present in the expression are balanced or not. Brackets are balanced if the bracket which opens last, closes first. You need to return true if it is balanced, false otherwise. Note: This problem was asked in initial rounds in Facebook Note:- I try to solve this problem using Linked List, python Queue, and List Sample Input 1 : { a + [ b+ (c + d)] + (e + f) } Sample Output 1 : true Sample Input 2 : { a + [ b - c } ] Sample Output 2 : false

Code : Stack Using LL

You need to implement a Stack class using a linked list. The data members should be private. Implement the following public functions : 1. Constructor - Initialises the data member (i.e. head to null). 2. push : This function should take one argument of type T and has return type void. This function should insert an element in the stack. Time complexity should be O(1). 3. pop : This function takes no input arguments and has return type T. This should removes the last element which is entered and return that element as an answer. Time complexity should be O(1). 4. top : This function takes no input arguments and has return type T. This should return the last element which is entered and return that element as an answer. Time complexity should be O(1). 5. size : Return the size of stack i.e. count of elements which are present ins stack right now. Time complexity should be O(1). 6. isEmpty : Checks if the stack is empty or not. Return true or false. ...

Horner rule

Given a polynomial of the form c n x n  + c n-1 x n-1  + c n-2 x n-2  + … + c 1 x + c 0   and a value of x, find the value of polynomial for a given value of x. Here  c n , c n-1 , ..  are integers (may be negative) and n is a positive integer.

Popular posts from this blog

MySQL Multi Source Master Slave Replication using GTID

Setting Up PostgreSQL Logical Replication with Docker Compose

Regex 101: An Introduction to Regular Expressions for Developers