instruction_seed
stringlengths
0
26.4k
source
stringclasses
4 values
Implement a JavaScript function that takes an array of integers as input and returns a new array containing only the prime numbers. The function should have a time complexity of O(n^2) and use only a single loop. Additionally, the function should not use any built-in JavaScript methods or external libraries for prime n...
codefeedback
Write a JavaScript function that takes a number as an argument and finds the sum of all the numbers in a given range (based on the given number). The range should be a random sequence of numbers that are generated based on a certain condition. The condition is that each number in the range should be a prime number grea...
codefeedback
Explain the differences between an array and an ArrayList in Java, and provide a code example that demonstrates a common error when working with an ArrayList. Additionally, discuss the performance implications of using an array versus an ArrayList in different scenarios.
codefeedback
Write a program to calculate the factorial of a given number using a recursive function. The program should prompt the user to enter a positive integer and then display the factorial of that number. Additional Requirements: 1. Handle the case when the user enters a non-positive integer by displaying an appropriate err...
codefeedback
Write a code to perform linear search in an array of integers and return the indices of all occurrences of the target element. If the target element is not found, return an empty list. The code should have a time complexity of O(n), where n is the size of the array. Additionally, you are not allowed to use any built-in...
codefeedback
Create a function in C++ that takes in two arrays of integers, multiplies each element of the first array by the corresponding element in the second array, and then returns the resulting array. Requirements: - The function should have a time complexity of O(n), where n is the length of the input arrays. - The function...
codefeedback
Write a JavaScript method to toggle font size on a webpage. The method should also keep track of the current font size and toggle it between a minimum font size of 12px and a maximum font size of 24px. Additionally, the method should display a confirmation message whenever the font size is changed. The method should al...
codefeedback
Given a string consisting of alphanumeric characters, separate it into left and right parts so that the left part contains only digits and the right part contains only lowercase letters. The left part should also be sorted in non-decreasing order. If there are no lowercase letters in the string, return an empty string ...
codefeedback
Parse the following XML document and print out the 'name' fields of all the nodes, but exclude any nodes where the 'age' field is greater than 25. Additionally, sort the printed names in ascending order based on the 'age' field. Note: You can assume that the XML document contains nested nodes and multiple occurrences ...
codefeedback
Modify the existing code to enable user input so the user can enter their own number and have the average of those two numbers returned. Additionally, handle any potential errors that may occur during the user input process. def find_average(a, b): try: num1 = float(input("Enter the first number: ")) ...
codefeedback
Develop a Python script to find and print the squares of the first 10 prime numbers. You should not use any pre-existing libraries or functions for finding prime numbers.
codefeedback
Write a C++ program to print the following pattern. 1 2 3 4 5 6 7 8 9 10 The program should take an integer input from the user and print the pattern based on that input. For example, if the user enters 6, the pattern should be: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 The program should handle input v...
codefeedback
Design a data structure that can be used to store student records with the fields 'name', 'age', 'major', 'graduation_year', and 'GPA'. The GPA field should be represented as a floating-point number between 0 and 4, inclusive. Additionally, the data structure should support efficient searching for students based on the...
codefeedback
Create a function to find the area of a circle by taking the radius as an argument. The radius should be a positive integer greater than 0 and less than or equal to 10^9. The function should handle the case when the radius is 0 or negative, returning an appropriate error message. The function should also handle the cas...
codefeedback
Create a function that takes a string and an integer as input and returns a string where each character is repeated n times. The function should also remove any duplicate characters in the input string before repeating the characters.
codefeedback
Design a relational database schema for a library that stores book information such as title, subject, and author. Additionally, the schema should include tables for tracking book availability, borrower information, and due dates. The borrower information should include fields for name, contact information, and a uniqu...
codefeedback
Write a JavaScript method for validating a form that has at least 10 input fields and requires the user to input a valid email address and a password with a minimum of 12 characters. The form should also have a checkbox that the user must check before submitting the form. Additionally, the form should include a select...
codefeedback
Write a code to add two matrices of any size, but the matrices must have the same number of rows and columns. Additionally, you must implement the matrix addition using recursion instead of iteration.
codefeedback
Develop a function in Python which prints the name of the day (eg. "Monday") given any date as an argument. The function should also check if the given date is a public holiday in a specific country and print a corresponding message. The function should handle dates from January 1st, 1900 to December 31st, 2099. Additi...
codefeedback
Write a code to print out all prime numbers between 1 and n without using a loop. Additionally, the code should have a time complexity of O(log n) and a space complexity of O(1).
codefeedback
Write a MySQL query to select records that are older than 3 months and younger than 5 years, and where the record's status is 'active'. Additionally, include records that have a status of 'pending' and 'inactive', but exclude records that have a status of 'archived'.
codefeedback
Describe a method for sorting a list of integers using selection sort. Write a function named `selection_sort` that takes in a list of integers as a parameter and returns the sorted list. In the `selection_sort` function, implement the selection sort algorithm to sort the list in ascending order. The selection sort ...
codefeedback
Rewrite the following JavaScript code to use arrow functions instead of regular functions. Additionally, ensure that the function only accepts positive integers as inputs and that it returns the sum of the squares of all the positive even integers within the given range.
codefeedback
Create a function that shifts an array by k positions to the right. The function should take three parameters: an array (arr), a positive integer (k), and a boolean value (wrap). The function should return a new array where the elements of the original array are shifted k positions to the right. If k is greater than...
codefeedback
Construct an object in JavaScript where the key is a positive integer from 1 to 1000 and the value is an array of prime numbers less than or equal to the key. The object must be implemented using a class and should include a method to check if a given key exists in the object. Additionally, the implementation should ha...
codefeedback
Create an array of n Strings, where each string should have at least m characters. The length of each string should be between m and 2m characters, inclusive. The values of n and m should be provided as input to the program.
codefeedback
Write a SQL query to find the ids, names, and email addresses of all users in the Users table who have address "New York" and whose email addresses contain the domain "gmail.com" and have made at least 3 purchases.
codefeedback
Write a C++ program to declare and initialize a two-dimensional array of numbers, and then find the sum of all the elements in the array. However, you are now required to exclude any negative numbers from the calculation of the sum.
codefeedback
Create an interface in C++ with two methods, one that takes an integer and one that takes a string. The integer parameter must be a positive number less than 10^6, and the string parameter must be a non-empty string with a maximum length of 100 characters. The integer parameter must be checked for primality before any...
codefeedback
Suggest a way to comment out a block of code in C++, ensuring that the commented block is still visible to an automated code analysis tool, while also optimizing the commenting technique for code readability and maintainability. Additionally, propose a method to automatically generate and update documentation based on ...
codefeedback
Write a code to train a sentiment classification model on the IMDB sentiment analysis dataset. In addition to training the model, you should also implement a method to evaluate the model's performance using appropriate metrics such as accuracy, precision, recall, and F1 score. To increase the difficulty, you should a...
codefeedback
Create a SQL query that performs a SELECT operation on a table "employee" with columns Id, Name, Age, Address, and Salary. The query should return the Name, Age, Address, and Salary of employees who are older than 30 years, have a salary greater than 5000, and whose addresses contain the word "Street". The query should...
codefeedback
Write a SQL query to print all the data in a table "scoreboard" with columns "name", "score", "category", and "rank". The rank should be calculated based on the score, with the highest score receiving rank 1 and the lowest score receiving the highest rank. In case of ties, the rank should be assigned based on the alpha...
codefeedback
Convert the following character stream into a number. However, there may be some erroneous characters in the stream that need to be handled correctly. Additionally, the input character stream may contain multiple numbers separated by non-numeric characters, and the program should extract and sum all the valid numbers f...
codefeedback
Write a function in JavaScript that takes in a string as input and returns an array of characters, while also reversing the order of the characters in the resulting array. The function should also remove any duplicate characters from the array and sort the remaining characters in descending order based on their ASCII v...
codefeedback
Write CSS code to style a list of items with the following requirements: - Each item should have a unique background color, with a gradient effect from top to bottom. - The font size should increase by 2 pixels for each subsequent item in the list. - The font weight should start at bold for the first item, and decrease...
codefeedback
Write a Python function to create a matrix of given size filled with random integers between -100 and 100, where each integer in the matrix must be unique. Constraints: - The size of the matrix will be at least 10x10. - The size of the matrix can be up to 100x1000.
codefeedback
Write a code to get the current weather information for a given city using only HTTP requests and without using any third-party libraries or APIs. Additionally, handle any errors or exceptions that may occur during the HTTP request.
codefeedback
Illustrate the procedure for creating a database table with the following constraints: the table must have at least 10 columns, two of the columns should have unique constraints, and two columns should have foreign key constraints referring to two different tables. Additionally, one of the foreign key constraints shoul...
codefeedback
Explain the purpose and use of try-catch statements in Java, and provide an example code demonstrating their implementation. Additionally, analyze and discuss the advantages and disadvantages of using try-catch statements compared to other error handling mechanisms in Java, such as throwing and catching custom exceptio...
codefeedback
Write a function that expects a string as a parameter and returns the most frequently occurring word with the length greater than three. The function should ignore punctuation and be case insensitive. Example: Input: "This is a test string. This is a test." Output: "test" Constraints: - The input string can contain a...
codefeedback
Write a Java program to define a class for a Dice object that simulates rolling a 20-sided die. 1. Create a class called Dice. 2. Add a private instance variable called sides of type int to store the number of sides on the dice. 3. Create a constructor that takes an int parameter called numSides and assigns it to the ...
codefeedback
Outputs the sum of all blocks in the following oracle database table, where the order_id is a unique identifier and the quantity and price are positive integers. Additionally, the sum should only include blocks where the quantity is greater than or equal to 5 and the price is less than or equal to 200. However, due to ...
codefeedback
Create an event handler for the onmouseover event in HTML. The event handler should dynamically change the color of the element being hovered over based on a randomly generated RGB value, and also display a tooltip with the element's ID, class, and the RGB value used to change its color. To achieve this, you need to p...
codefeedback
Suggest a code to do the following task: Input a string and output the count of all the characters occurring in the string, excluding any special characters. The code should handle both uppercase and lowercase letters as separate characters. Additionally, the code should not use any built-in functions or libraries for ...
codefeedback
Write a Python program to find the group of three numbers in a list that has the greatest product. The list will contain both positive and negative integers, and may also contain zeroes. You may assume that the list will always have at least three elements. In addition to the given requirements, implement the followin...
codefeedback
Check if the given string contains any uppercase characters and at least one of the following special characters: !@#$%^&*()-_=+[]{},.<>/?;':"\|`~. If the string meets these criteria, output the count of uppercase characters and the positions of all special characters in the string. Otherwise, output a message stating ...
codefeedback
Output the name of the variable type in the following expression. You must also determine if the given expression is a complex number or not. Additionally, you need to check if the given expression is a valid input or not. Expression: 5 + 6j To determine the variable type, you need to perform the following steps: 1...
codefeedback
Write a code to generate a random password containing at least two symbols, two numbers, two lowercase letters and two uppercase letters. Additionally, the password must not contain any repeated characters.
codefeedback
Create a SQL query to select the rows with column B equal to "test" and column C equal to "example", while excluding any rows where column A is a multiple of 3. Additionally, the query should only return the distinct rows and order the result by column B in descending order.
codefeedback
Implement a function to concatenate two arrays, but you are not allowed to use any built-in array concatenation methods or functions. You must write your own logic to concatenate the arrays. Additionally, the function should also remove any duplicate elements from the resulting concatenated array. Array 1: [1,2,3,4,5]...
codefeedback
Generate 10 random numbers between 1 and 20 using a PHP script. Sort the numbers in descending order and display them in a space-separated format. Additionally, ensure that the generated numbers are unique and do not include any duplicates. Finally, calculate the sum of all the generated numbers and display it.
codefeedback
Write a function that takes a string as input and returns the HTML element for displaying a hyperlink. The function should support both absolute and relative URLs. Constraints: - The input string will always be a valid URL. - The function should have a time complexity of O(1). - The function should validate the URL be...
codefeedback
Generate an algorithm that creates a Fibonacci sequence with a specified length, where each number in the sequence is a prime number. #Explanation# The modified problem now requires generating a Fibonacci sequence with a specified length, but with the added constraint that each number in the sequence must be a prime n...
codefeedback
Create a MySQL database named "cinema" and within that database, create a table named "movies" with the following columns: 1. id: a unique identifier for each movie. 2. title: the title of the movie. 3. release_date: the date on which the movie was released. 4. genre: the genre(s) of the movie. This column should allo...
codefeedback
Add a tag 'img' with attribute 'src' and value 'image.jpg' in the following xml document. However, the 'img' tag should only be added if it does not already exist in the document. <?xml version="1.0" encoding="UTF-8"?> <information> <property> <name>Adobe</name> <type>Software</type> <img src="image.jpg"></img>...
codefeedback
Generate a code to identify duplicate elements in a list and count the number of occurrences for each duplicate element. Your code should have a time complexity of O(n), where n is the size of the input list. Additionally, you are not allowed to use any built-in functions or data structures for this task.
codefeedback
Create a MySQL query to group a table of student records by their country of origin, but exclude any students whose age is below 18 and whose last name starts with the letter "S".
codefeedback
Write a CSS code to put a shadow on all the paragraphs, but only if the paragraph contains more than 10 words and has a font size larger than 14 pixels. Additionally, the shadow should have a blur radius of 5 pixels and be colored with a linear gradient, transitioning from a light blue to a dark blue shade.
codefeedback
Create a class called 'Person' which has a constructor that creates a person with a given name and age. The name should be a string and must not contain any special characters or numbers. The age should be an integer between 18 and 100, inclusive. If the age is not within this range, raise an exception with a custom er...
codefeedback
Create a Java class named "Card" to represent a standard playing card. The class should contain a constructor which takes the card's suit and number as parameters. The suit should be a string that can only be one of the following: "Spades", "Hearts", "Diamonds", "Clubs". The number should be an integer between 1 and 13...
codefeedback
Design a data structure to store a list of numbers and their frequencies, where each number can occur multiple times in the list. Additionally, the data structure should support the following operations: 1. Add a number to the list. 2. Remove a number from the list. 3. Update the frequency of a number in the list. 4. ...
codefeedback
Edit the following HTML form to validate an email address and display an error message if the email is not valid. Additionally, implement the following requirements: 1. The email address must not contain any special characters such as !, #, $, %, etc. 2. The email address must not start with a number. 3. The email addr...
codefeedback
Create a C# class that contains two private fields, one public method, and one property. The class should also implement an interface that requires the implementation of a custom event. The event should be triggered whenever the property's value is changed. Additionally, the class should include a static method that ca...
codefeedback
Produce a program to print out the frequency of characters in a word. However, your program should ignore any characters that are not letters (a-z or A-Z) and should not be case sensitive. Additionally, you need to print the characters in descending order based on their frequency. Example: Input: "Hello World" Output:...
codefeedback
Re-write the following method to use a single loop instead of two, and also calculate the sum of all even indices in the array. Additionally, implement the method to have a time complexity of O(n log n), where n is the size of the array. def sum_special(arr): temp = 0 for i in range(0, len(arr), 2): te...
codefeedback
Write an Angular directive that creates a form with multiple input fields and performs validation on each field. Requirements: 1. The directive should create a form with at least 5 input fields, each with its own validation requirements. 2. The validation requirements should include checking for empty fields, minimum ...
codefeedback
Suggest a Python code to filter a list of numbers, which are integers ranging from -1000 to 1000, so that all even numbers are removed. Additionally, the code should only use a single loop and should have a time complexity of O(n), where n is the length of the input list. The code should not use any built-in functions ...
codefeedback
Generate a random list containing 20 elements, where each element is a prime number between 0 and 50.
codefeedback
Generate an array of random integers between 1 and 100 inclusive, where no two adjacent numbers in the array are the same. Additionally, the array should be sorted in non-decreasing order.
codefeedback
Create a function that takes in a string of alphanumeric characters and special symbols, and returns the string without its last two letters. The input string can be up to 100 characters long and may contain uppercase and lowercase letters, numbers, and special symbols such as @, #, $, %, etc. Additionally, the functio...
codefeedback
Suggest a JavaScript code to validate a username if it contains only alphabets and digits while ignoring the special characters. Additionally, the code should also check for the minimum and maximum length of the username, which should be between 6 and 20 characters. The code should also ensure that the username starts ...
codefeedback
Write a code to find the longest consecutive sequence inside of a given list of numbers, where the sequence must be strictly increasing by exactly 1 and contain at least five elements. Additionally, the code should output the start and end indices of the longest consecutive sequence.
codefeedback
Create a sorting algorithm to sort a given list of numbers from lowest to highest, without using any built-in sorting functions or methods. Additionally, your algorithm must not use any additional data structures such as arrays or lists, and must sort the numbers in place within the original list. Ensure that your algo...
codefeedback
Construct an HTML form with 10 fields, one for each of the following: name, email address, age, gender, job title, phone number, address, city, state, and zip code. Additionally, implement form validation to ensure that the email address field follows a specific format: it must contain a valid domain name and end with ...
codefeedback
Please write a PHP function that takes in a string as input and returns a new string where each word in the input string has its first letter capitalized. The function should preserve the original case of the remaining letters in each word. Additionally, the function should also capitalize the first letter of the input...
codefeedback
Generate a random number between 10 and 35 in JavaScript, but the number must be divisible by 5 and should also be a prime number.
codefeedback
Design a query in MongoDB to select documents based on the following criteria: 1. The array field must contain at least three specific values. 2. The total marks of the selected documents should be greater than the average total marks of all documents. 3. The documents should be sorted in descending order of their tota...
codefeedback
Please write a Python class for a Triangle object with the following instance attributes and methods: - side1 (a positive integer) - side2 (a positive integer) - side3 (a positive integer) Methods: - `get_area()` - returns the area of the triangle - `get_perimeter()` - returns the perimeter of the triangle - `is_equil...
codefeedback
Create an object in JavaScript that has four properties and four associated values, where each property represents a different type of data structure (such as array, object, set, or map) and each value represents a specific implementation or usage of that data structure. Additionally, each value should be unique and ca...
codefeedback
Check if a given string contains all the alphabets in a specific order. The alphabets must appear consecutively and in the same order as they do in the English alphabet. The function should return the starting index of the substring that satisfies the condition. If no such substring exists, return -1. Example: Input: ...
codefeedback
Increase the difficulty of the given programming test question by adding more complex requirements and constraints: Create an SQL table called "Employees" with the following columns and necessary parameters: 1. "EmployeeID" - unique identifier for each employee, set as the primary key and auto-incremented. 2. "FirstNa...
codefeedback
Implement a non-recursive depth-first search (DFS) algorithm to traverse a binary tree in Python. The algorithm should return a list of values in the order they are visited. The time complexity of the algorithm should be O(n), where n is the number of nodes in the tree. Additionally, the space complexity should be O(h)...
codefeedback
Design a C program to create a scientific calculator that supports advanced mathematical functions such as trigonometric operations (sin, cos, tan), logarithmic operations (log, ln), exponential operations (e^x), and factorial calculation. Additionally, the calculator should have a memory feature that allows the user t...
codefeedback
Write an HTML code to create a table with five columns containing the headers "ID", "First Name", "Last Name", "Group", and "Grade". Additionally, each cell in the "ID" column should only accept numeric values between 1 and 1000 (inclusive), the "First Name" and "Last Name" columns should only accept alphabetical chara...
codefeedback
Write a Java program to find the kth smallest element in an unsorted array of integers, where k is a positive integer less than or equal to the length of the array. Additionally, your program should have a time complexity of O(n log k), where n is the length of the array.
codefeedback
Rewrite the following PHP code to add a new item to the array only if it is not already present. The new item should be in lowercase and should not contain any special characters. Additionally, the code should ensure that the resulting array is sorted in ascending order. $my_array = array('apple', 'orange');
codefeedback
Write an SQL query to update the salary of all employees with the title 'Manager' to $50000, but only if their hire date is before January 1st, 2020 and they have been with the company for at least 5 years.
codefeedback
Write a C++ code to create a vector of integers and then sort them in increasing order. The vector may contain duplicate elements. vector<int> v = {3, 1, 5, 4, 7, 2, 3, 6, 4}; Additionally, you are required to implement your own sorting algorithm instead of using any built-in sorting functions or libraries. The time c...
codefeedback
Implement a function in Python that can sort a list of integers in descending order. Your function should have a time complexity of O(n^2), where n is the length of the input list. Additionally, the function should use the Bubble Sort algorithm to sort the list. Bubble Sort is an inefficient sorting algorithm that rep...
codefeedback
Write a function in Python that takes a number n as its parameter and returns the sum of the cubes of the first n prime numbers.
codefeedback
Write code to create a function in JavaScript to reverse a given array without using the built-in reverse() method. The function should take an array as input and return a new array with the elements in reverse order. Example: Input: [1, 2, 3, 4, 5] Output: [5, 4, 3, 2, 1] You are not allowed to use the reverse() met...
codefeedback
Write a JavaScript function that hides an element after a specified number of seconds. The function should take two parameters: the element to be hidden and the number of seconds to wait before hiding the element. Additionally, the function should only hide the element if it is visible, and should display an error mess...
codefeedback
Construct a regex expression to capture words starting with 'cat' and ending with 's', with a minimum length of 7 characters and containing at least one vowel.
codefeedback
Design a function to calculate the standard deviation of a set of data that may contain duplicates and negative numbers. The function should have a time complexity of O(n) and a space complexity of O(1). The input list can contain up to 10^6 elements, and the function should be able to handle it efficiently. The functi...
codefeedback
Access the 3rd element in a JSON Array of objects. Each object should have a "name" property and a "score" property. Additionally, each object should have a nested array called "grades" that contains a list of integers representing individual test scores. Find the average of all the test scores for the 3rd element.
codefeedback
Extract the extension from a given filename string, but the program should also validate if the filename meets the following requirements: it must start with a letter, can only contain alphanumeric characters and underscores, and the extension must be either "txt", "csv", or "xlsx". Additionally, the program should als...
codefeedback
Using HTML5 and JavaScript, create a canvas element with a width of 1000px and a height of 500px. Implement a drawing application that allows users to draw on the canvas using their mouse. The drawing should consist of multiple shapes, such as lines, rectangles, circles, and polygons. Users should be able to choose the...
codefeedback
List the type of loops in Python and write a program that takes a list of integers as input and calculates the sum of all even numbers using a while loop. The program should also calculate and display the average of all odd numbers in the list. Additionally, the program should only consider numbers within the range of ...
codefeedback
Write a function in Python that sorts a dictionary by values in descending order, excluding any values that are multiples of 3. If two values are equal, the one with the higher ASCII value of the corresponding key should come first in the sorted list. The function should return a list of tuples, where each tuple contai...
codefeedback