Repeated Character Whose First Appearance is Leftmost


Given a string, find the repeated character present first in the string.


Examples:


Input  : geeksforgeeks
Output : g
(mind that it will be g, not e.)

Input  : abcdabcd
Output : a

Input  : abcd
Output : -1
No character repeats

Asked in: Goldman Sachs internship

We have discussed different approaches in Find repeated character present first in a string.

How to solve this problem using one traversal of input string?


Method 1 (Traversing from Left to Right)
We traverse the string from left to right. We keep track of the leftmost index of every character. If a character repeats, we compare its leftmsot index with current result and update the result if result is greater

#include <bits/stdc++.h>

using namespace std;

#define NO_OF_CHARS 256

  

int firstRepeating(string& str)

{

    

    

    int firstIndex[NO_OF_CHARS];

    for (int i = 0; i < NO_OF_CHARS; i++)

        firstIndex[i] = -1;

  

    

    

    

    

    int res = INT_MAX;

    for (int i = 0; i < str.length(); i++) {

        if (firstIndex[str[i]] == -1)

           firstIndex[str[i]] = i;

        else

           res = min(res, firstIndex[str[i]]);

    }

  

    return (res == INT_MAX) ? -1 : res;

}

  

int main()

{

    string str = "geeksforgeeks";

    int index = firstRepeating(str);

    if (index == -1)

        printf("Either all characters are "

               "distinct or string is empty");

    else

        printf("First Repeating character"

               " is %c",

               str[index]);

    return 0;

}

Output:


First Repeating character is g

Time Complexity : O(n). It does only one traversal of input string.
Auxiliary Space : O(1)


Method 2 (Traversing Right to Left)
We traverse the string from right to left. We keep track of the visited characters. If a character repeats, we update the result.

#include <bits/stdc++.h>

using namespace std;

#define NO_OF_CHARS 256

  

int firstRepeating(string& str)

{

    

    bool visited[NO_OF_CHARS];

    for (int i = 0; i < NO_OF_CHARS; i++)

        visited[i] = false;

  

    

    

    int res = -1;

    for (int i = str.length() - 1; i >= 0; i--) {

        if (visited[str[i]] == false)

            visited[str[i]] = true;

        else

            res = i;

    }

  

    return res;

}

  

int main()

{

    string str = "geeksforgeeks";

    int index = firstRepeating(str);

    if (index == -1)

        printf("Either all characters are "

               "distinct or string is empty");

    else

        printf("First Repeating character"

               " is %c",

               str[index]);

    return 0;

}

Output:


First Repeating character is g

Time Complexity : O(n). It does only one traversal of input string.
Auxiliary Space : O(1)

The method 2 is better than method 1 as it does fewer comparisons.




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 :



1

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








Source link

What is the WWE Network


Java Tutorial Point | Javatpoint Java | Core Java Tutorialspoint | Java Programming: What is the WWE Network

Pages

What is the WWE Network

The announcement by WWE back in February, 24, 2014, that it was intending to launch its own Nefflix-like streaming service was met with skepticism. Quite a few could have foreseen the growth we have witnessed over the 4 years since its launch. The platform referred to as the WWE Network would allow the WWE Universe to enjoy streaming services of WWE content upon subscription. With more than 2 million subscribers today, the streaming service has significantly increased the revenues generated by the WWE Corporation. Subscribers pay a monthly subscription fee of about $10 – $15 and they reserve the right to cancel their subscription at any time Besides, the first month of subscription is free. Prior to delving into the increase in the number of subscribers to the Network, it is imperative to have a basic understanding of the platform. 
What is the WWE Network? WWE Network is a Netflix-like streaming service that is owned by the WWE. It allows the WWE Universe to stream videos from WWE. These videos range from pay per view events like the recent WrestleMania and the upcoming Greatest Royal Rumble in Saudi Arabia later this month and Backlash in May all for free upon subscription. Subscribers also have access to unlimited WWEs premium content that is available anytime, anywhere and on any device. They also have access to WWE documentaries, original series, reality shows and in ring specials like Cruiserweight Classic in addition to the exclusive access to the weekly in ring premier shows. They may also enjoy replays of their favourite SmackOown live and Raw episodes that are available on demand for 30 days following the airing of the episode. WWE Network allows the WWE Universe to watch current WWE content and even WWE shows from decades ago. It allows subscribers to get entertained by ensuring they get access to 10,000+ hours of WWE content. 
Growth of the VVWE Network. After somewhat of a teaser back in 2011, the WWE finally launched the WWE Network in the early months of 2014. It was launched in February, 24, 2014, in the US and it came with a free trial period in the week of the launch. In April, 2014, WWE Corporation announced that the streaming service had already gotten 667,000 subscribers. This was just shy of the 1 million subscribers targeted to break even. This shortfall had adverse effects on investors and in an effort to allay their fears, WWE opted to offer yet another free preview week of the Network. This was solely intended to increase the number of subscribers. Later in July, the WWE in their financial report indicated that they had gotten a total of 700,000 subscribers. The company had set its sights in attaining more than 1 million subscribers before the start of 2015. In July, 2014, WWE announced a deal that would see the corporation distribute the Network as a premium television service. On the same day, the platform expanded to other countries like Spain, New Zealand and Singapore among others. Further expansion followed or was scheduled along the years. These expansions were in an effort to increase the potential user bas. Today, the Network has coverage in about 190 countries worldwide. As of October, 30, 2014, the subscription to the streaming service stood at around 731,000 subscribers. In an attempt to further increase this number, the company dropped the mandatory 6-month subscription and subscribers were then allowed to cancel their subscriptions at any time An announcement by the WWE towards the and of January, 2015 put the subscription to the streaming service at more than a million. Vince McMahon promised subscribers that the company would focus on adding value and more content to the platform in the course of the year. Later in February, the company launched the Network in North Africa and in the Middle East as a premium service. During the trading period report of the second quarter of 2015, the VVWE reported that the Network had 1.156 million subscribers. This was a 13% decline from the 1.315 million subscribers reported in the first quarter of the trading period. The 1.156 million reported subscribers represented the paid subscribers. However, in addition to the trial subscribers, the gross subscription to the Network stood at 1227 million users. A report by Park Associates in November, 2015, showed that the VVWE Network had entered the top 5 of streaming service. This was an incredible achievement and the platform only came second in the sports category behind MLB.tv. The WWE announced that the Network had 1.949 million subscribers in April, 2017. In this figure, 1.661 were paid subscribers. Close to 70% of the subscribers to the WWE Network are from the States. Only about 30% come from other countries. To try and curb this and to increase the number of subscribers to the Network, WWE has tried to ensure that there is coverage of the streaming service worldwide. The Network is available in about 191 countries. It is unavailable in only 13 countries though its coverage in China is limited to Hong Kong. In April, 9, 2018, WWE announced that subscription to its streaming service had reached a record 2.12 million subscribers. This rise could be mainly attributed to the iconic WrestleMania pay per view event that had taken place the previous day. Within this figure, about 1A1 million were paid subscribers. The increase in the total paid subscribers to the WWE Network has seen significant increase in the revenues generated by the WWE. According to the projections of the first quarter of this year (2018), the company expects revenues from the Network to exceed $30 million 01BDA. The WWE also expects an increase in the number of paid subscribers to about 177 million by the end of the second quarter of this year. The company predicts that the income generated from the Network would exceed the anticipated $140 million by about $5 million. 
The WWE Network continues to be an valuable asset for both WWE Corporation and the WWE Universe. The streaming service allows subscribers access to unlimited WWE content plus free live coverage of all pay per view events. The streaming services offered have proven quite attractive as the number of subscribers keeps growing and is expected to continue growing and possibly surpass the 2 million mark for paid subscribers by the end of this year 


Internships in Aeronautical Engineering



Bangalore Internships - Aeronautical Engineering

Sanfoundry located at Bangalore offers internships to deserving B.Tech/M.Tech Students in Aeronautical Engineering Branch. In Aeronautical Engineering internships offered by Sanfoundry, shortlisted interns will be working towards the creation of useful artifacts like questions and answers, tutorials, articles, real-world problems and solutions on Aeronautical Engineering. Moreover, every intern working on Aeronautical Engineering internship will focus on one specific subject under the Aeronautical branch. This will help the intern to develop an in-depth understanding of that particular subject in their branch.

Here’s the list of topics for Internship in “Aeronautical Engineering”.

  • Machine Design
  • Kinematic of Machines
  • Dynamics of Machines
  • Manufacturing Engineering I
  • Manufacturing Engineering II
  • Fluid Mechanics
  • Avionics
  • Aerodynamics – I
  • Machine Drawing
  • Aircraft Structures – I
  • Aircraft Structures – II
  • Aircraft Performance
  • Applied Thermodynamics of Materials at Macro and Nano Scale
  • Aero, Marine, Metallurgical and Molecular Thermodynamics
  • Computational Fluid Dynamics
  • Aero Engine Maintenance and Repair
  • Industrial Pollution Control Engineering
  • Aircraft Materials and Processes
  • Elements of Aeronautics
  • Modeling and Finite Element Analysis
  • Finite Element Method and Analysis
  • Advanced Flight Dynamics
  • Flight Vehicle Design
  • Fluid Mechanics and Machinery
  • Advance Gas Turbine Engines Theory
  • Design of Composite Materials
  • Entrepreneurship Development, Management and Apparel Entrepreneurship
  • CFD in Manufacturing Processes
  • Numerical Modelling of Manufacturing Processes
  • Wind Energy Technology
  • Aerospace Materials and Manufacturing Processes
  • Advance Manufacturing Process Simulation and Management
  • Mechanics of Machines
  • Mechanics of Materials
  • Advance Mechanics of Materials
  • Applied Numerical Methods
  • Propulsion – I
  • Propulsion – II
  • Solid Mechanics for Technologists
  • Advance Theory of Vibrations
  • New Total Quality Management
  • Mechanical Vibrations
  • Aerodynamics – II
  • Computer Aided Machine Drawing
  • Applied Gasdynamics
  • Aircraft Stability and Control
  • Artificial Intelligence
  • Microprocessor and Peripherals
  • Hydraulics
  • Agile Manufacturing Technologies
  • Air Traffic Control Services and Procedures
  • Aircraft General Engineering and Maintenance Practices
  • Aircraft Maintenance, Repair and Overhaul
  • UAV Systems
  • Aircraft Safety Rules and Regulations
  • Airframe Maintenance and Repair
  • Total Quality Management
  • Boundary Layer Theory
  • Advanced Thermodynamics and Combustion
  • Theory and Design of Plates and Shells
  • Computer Integrated Manufacturing and Automation
  • Disaster Mitigation and Management
  • Experimental Aerodynamics
  • Fatigue and Fracture Mechanics
  • Flight Testing
  • Fracture Mechanics, Fatigue and Analysis of Engineering Failures
  • Guidance and Navigation
  • Two Phase Flow and Heat Transfer
  • Helicopter Dynamics
  • Helicopter Theory
  • Hypersonic Aerodynamics
  • Aerospace Quality Assurance
  • Micro and Smart Systems Technology
  • Numerical Methods in Fluid Flow Problems
  • Computer Science and Operation Research
  • Modelling and Optimisation in Flexible Manufacturing System
  • Reliability Engineering Basic Principles
  • Industrial Robotics
  • Rockets and Missiles
  • Smart Materials and Structures
  • Vibration and Structural Dynamics
  • Introduction to Aeroelasticity
  • Aeroelasticity
  • Advanced Aeroelasticity
  • Pneumatics
  • Engineering Mathematics
  • Engineering Physics
  • Engineering Chemistry
  • Engineering Mechanics
  • Engineering Drawing
  • Environmental Science and Engineering
  • Basic Electrical Engineering
  • Elements of Civil Engineering
  • Algorithms and Data Structures – 1
  • Algorithms and Data Structures – 2
  • Applied Chemistry
  • Differential and Difference Equations
  • Advance Engineering Mathematics
  • Basic Electronics Engineering
  • Partial Differential Equations and Transform Theorems
  • Computer Aided Engineering Drawing
  • Multivariable Calculus and Differential Equations
  • Probability and Statistics
  • Applications of Differential and Difference Equations
  • Elements of Mechanical Engineering
  • Sanfoundry is looking for Interns who are passionate about their field of study and like core subjects in Aeronautical Engineering. Every intern contributes to Sanfoundry’s Global learning project during their internship and is Mentored and Guided by our Founder and CTO. If you are interested to contribute and apply, here’s full detail of Sanfoundry’s Internship Program.

     
    Sanfoundry Global Education & Learning Series – Aeronautical Engineering Internships!




    Manish Bhojasia, a technology veteran with 20+ years @ Cisco & Wipro, is Founder and CTO at Sanfoundry. He is Linux Kernel Developer & SAN Architect and is passionate about competency developments in these areas. He lives in Bangalore and delivers focused training sessions to IT professionals in Linux Kernel, Linux Debugging, Linux Device Drivers, Linux Networking, Linux Storage, Advanced C Programming, SAN Storage Technologies, SCSI Internals & Storage Protocols such as iSCSI & Fiber Channel. Stay connected with him @
    LinkedIn | Facebook | Twitter



    Source link

    Congnizant ( CTS ) Placement Preparation




    Be the First to upvote.

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







    Source link

    Java 8 Functional Interfaces


    Introduction to functional interfaces

    A functional interface is an interface that has a single abstract method.  Functional interfaces can have multiple static and default methods, but they should have only one abstract method to qualify as a functional interface. Functional interfaces were introduced in Java 8 in order to implement lambda expressions.

    Code Sample

    The following code defines a functional interface called DemoFunctionalInterface.

    package demo;
    
    @FunctionalInterface
    
    public interface DemoFunctionalInterface {
    
        public void myAbstractMethod();
    
    
        public default void myDefaultMethod() {
    
            System.out.println("Default method");
    
        }
    
    
        public static void myStaticMethod() {
    
            System.out.println("Static method");
    
        }
    }

    So here, we have declared an interface called DemoFunctionalInterface. It has an abstract method called myAbstractMethod. Since there is only one abstract method present, this is a functional interface.

    In addition to the abstract method, this functional interface has two additional methods, one is a static method and the other is a default method.

    @FunctionalInterface annotation

    In the code above, the @FunctionalInterface annotation is specified on the interface. This marks the interface as a functional interface and forces the compiler to check that there is only one abstract method. So if this annotation is specified and if we try to add another abstract method, there will be a compilation error as can be seen in the following code:

    @FunctionalInterface
    
    public interface DemoFunctionalInterface {
         public void myAbstractMethod();
    
         //the following method causes compilation error
         public void anotherMethod();
    }

    The @FunctionalInterface annotation is optional. So if this annotation is removed, the compilation error goes away, but the interface will no longer be a functional interface.

    In general, any interface with a single abstract method is treated as a functional interface by Java. Irrespective of whether you use @FunctionalInterface annotation or not.

    Uses of Functional interfaces

    Java 8 introduced lambda expressions as the first step into functional programming. Using lambda expressions, you can provide inline implementations for functional interfaces. This helps make the code concise and gets rid of the boilerplate code.

    Suppose you need to implement the DemoFunctionalInterface declared above. Prior to Java 8, you would need to write code similar to the following:

    public class DemoClass implements DemoFunctionalInterface{
    
         @Override
         public void myAbstractMethod() {
              System.out.println("In myAbstractMethod");
         }
    
         public static void main(String args[]){
              DemoClass obj = new DemoClass() ;
              obj.myAbstractMethod();
         }
    }

    So basically you need to do the following:

    • Create a class that implements the interface
    • Override the abstract method
    • Write the code that invokes the implemented method

    So this seems like a lot of code to implement a single method. Java 8 solves this issue via functional interfaces and lambda expressions. So we can re-write the code above as follows:

    public class DemoClass2 {
         public static void main(String[] args) {
              DemoFunctionalInterface obj = () -> System.out.println("In myAbstractMethod");
              obj.myAbstractMethod();
         }
    }

    Compared to the pre-Java 8 code, this code is quite concise. A lambda expression is used to implement the myAbstractMethod. So, you do not need to create a class that implements the interface and you do not need to provide a method body.

    When you run this code, it will print the same output as before:

    method1

    In Built Functional Interfaces in Java

    Prior to Java 8, there were already interfaces like Runnable, Comparator etc with a single abstract method. After Java 8, they were designated as functional interfaces via the @FunctionalInterface annotation.

    In addition, Java 8 has added a new package called java.util.Function. It has a number of functional interfaces that can be used to perform some functions.

    Let us see how some of these can be implemented.

    Function Interface

    A function has a single method called apply. It accepts an object of any data type and returns a result of any datatype.

    Consider the following code:

    import java.util.function.Function;
    
    public class MyFunctionDemo {
         public static void main(String[] args) {
              Function<Integer,Double> squareRootGenerator = (input) -> {return Math.sqrt(input);};
              int input = 16;
              double result = squareRootGenerator.apply(input);
              System.out.println("Square Root of "+input+" is "+result);
         }
    }

    Code Explanation

    This Function implementation accepts an integer number and returns its square root. Function<Integer, Double> specifies that the input is of type Integer and output is of type Double. The lambda expression needs to be assigned to an instance of the functional interface, in this case, squareRootGenerator Finally, the squareRootGenerator.apply method is invoked which uses the code in the lambda expression to print the output.

    So when this code is executed, it will print the following output:

    Square Root of 16 is 4.0

    Supplier Interface

    The supplier has a single method called get. It does not accept any arguments. It returns an object of any data type.

    public class MySupplierDemo {
    
         public static void main(String[] args) {
              Supplier<Integer[]> randomNumberGenerator = () ->  {
                                                                       Integer[] result = new Integer[5];
                                                                       for(int i=0; i< result.length;i++){
                                                                            result[i] = new Random().nextInt(100);
                                                                       }
                                                                       return result;
                                                                  };
              System.out.println("Result:");
              Integer[] result = randomNumberGenerator.get();
              for(int num:result)
              System.out.println(num);
         }
    }

    This Supplier returns an Integer array of 5 random numbers. As before, the get method is implemented via a lambda expression which creates an Integer array of length 5 and populates it with 5 random numbers.

    So when this code is executed it will print output similar to the following:

    Result:

    53
    
    78
    
    19
    
    89
    
    16

    Consumer Interface

    The consumer has a single method called accept. It accepts a single argument of any data type and does not return any result. So it modifies the input object.

    Consider the code below:

    public class Person {
    
         private String name;
    
         private int age;
    
         Person(String name,int age){
              this.name=name;
              this.age=age;
         }
    // Getter and setter methods
    
    }
    import java.util.function.Consumer;
    
    public class MyConsumerDemo {
         public static void main(String[] args) {
              Consumer<Person> ageIncreaser = (input) -> {
                                                                                 int newAge = input.getAge()+5;
                                                                                 input.setAge(newAge);
              };
    
              Person person = new Person("abc",25);
              ageIncreaser.accept(person);
              System.out.println("New age:"+person.getAge());
         }
    }

    A Person class is declared with name and age fields. This Consumer accepts a Person object and increases the age of the person by 5.

    When this code is executed, it will print the following output:

    New age:30

    Conclusion

    Functional interfaces and lambda expressions provide a totally new way of programming for Java developers. They help in getting rid of the boilerplate code involved in implementing an interface and make the code concise.

    SERIES NAVIGATION

    << Variable shadowing


    Internships in Nano Technology Engineering



    Bangalore Internships - Nano Technology Engineering

    Sanfoundry located at Bangalore offers internships to deserving B.Tech/M.Tech Students in Nano Technology Engineering Branch. In Nano Technology Engineering internships offered by Sanfoundry, shortlisted interns will be working towards the creation of useful artifacts like questions and answers, tutorials, articles, real-world problems and solutions on Nano Technology Engineering. Moreover, every intern working on Nano Technology Engineering internship will focus on one specific subject under the Nano Technology branch. This will help the intern to develop an in-depth understanding of that particular subject in their branch.

    Here’s the list of topics for Internship in “Nano Technology Engineering”.

  • Basic Civil Engineering
  • Basic Electrical Engineering
  • Basic Mechanical Engineering
  • Biology for Engineers
  • Analog Electronic Circuits
  • Elements of Mechatronics Systems
  • Engineering Graphics and Drawing
  • Fourier Series, Partial Differential Equations and Its Applications
  • Fundamentals of Solid State Engineering
  • Immunology
  • Industrial Nanotechnology
  • Intelligent Manufacturing Technology
  • Knowledge Management Systems
  • Micro and Nanofabrication
  • Modelling Tools and Techniques for Micro, Nano Systems
  • Nanobiotechnology
  • Nanochemistry
  • Nanoelectronics
  • Nanophotonics
  • Numerical Methods and Its Application
  • Polymer and Nanocomposites
  • Principles of Engineering Metallurgy
  • Probability and Random Process
  • Programming Using Matlab
  • Quantum Mechanics
  • Statistical Mechanics and Thermodynamics of Small Systems
  • Synthesis and Characterization of Nanomaterials
  • Advanced Drug Delivery Systems
  • Atomistic Modelling
  • Carbon Nanotechnology
  • Green Nanotechnology
  • Introduction To Scientific Research
  • Lithography Techniques and Fabrication
  • MEMS and NEMS
  • Micro and Nanofluidics
  • Microelectronics and VLSI
  • Molecular Spectroscopy and Its Applications
  • Nano and Micro Emulsions
  • Nano-computing
  • Nano-medicine
  • Nanomagnetism
  • Supramolecular Systems
  • Robotics Engineering
  • Nanotechnology for Energy Systems
  • Nanotechnology in Agriculture and Food Processing
  • Nanotechnology In Cosmetics
  • Nanotechnology in Textiles
  • Nanotechnology in Tissue Engineering
  • Smart Sensor Systems
  • Nanotribology
  • Photovoltaic Technology
  • Surface and interfaces
  • Physics of Solid State Devices
  • Polymer Engineering
  • Advanced Calculus and Complex Analysis
  • Calculus and Solid
  • Chemistry
  • Elements Of Nanoscience and Nanotechnology
  • Geometry
  • Materials Science
  • Physics
  • Principles of Environmental Science
  • Sanfoundry is looking for Interns who are passionate about their field of study and like core subjects in Nano Technology Engineering. Every intern contributes to Sanfoundry’s Global learning project during their internship and is Mentored and Guided by our Founder and CTO. If you are interested to contribute and apply, here’s full detail of Sanfoundry’s Internship Program.

     
    Sanfoundry Global Education & Learning Series – Nano Technology Engineering Internships!




    Manish Bhojasia, a technology veteran with 20+ years @ Cisco & Wipro, is Founder and CTO at Sanfoundry. He is Linux Kernel Developer & SAN Architect and is passionate about competency developments in these areas. He lives in Bangalore and delivers focused training sessions to IT professionals in Linux Kernel, Linux Debugging, Linux Device Drivers, Linux Networking, Linux Storage, Advanced C Programming, SAN Storage Technologies, SCSI Internals & Storage Protocols such as iSCSI & Fiber Channel. Stay connected with him @
    LinkedIn | Facebook | Twitter



    Source link